Solved

sql server query

Posted on 2016-09-08
7
34 Views
Last Modified: 2016-09-08
I am trying to create a query that will tell me if the clientcodewordposition is in tbltagwords but not in tblwords.

I thought this would do it:
but it doest

SELECT TW.ClientCodeWordPosition, sub.ClientCodeWordPosition
FROM TblWordTags  TW LEFT JOIN TblWordTags ON (TW.ClientCodeWordPosition = TblWordTags.ClientCodeWordPosition)

join ( select W.ClientCodeWordPosition
	FROM TblWords W
	where w.ClientCodeWordPosition is null
	GROUP BY W.ClientCodeWordPosition ) sub

	on TW.ClientCodeWordPosition=sub.ClientCodeWordPosition
	GROUP BY TW.ClientCodeWordPosition, sub.ClientCodeWordPosition

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 3
  • 3
7 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41789279
What output are you wanting to get?
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 41789281
I'm not sure on what you pretend to do. Can you post some sample data for better understanding?
0
 

Author Comment

by:PeterBaileyUk
ID: 41789287
if pk in TblWordTags  is 'L5EMW_T_6' (ClientCodeWordPosition is pk field) and does not appear in tblWords (ClientCodeWordPosition is pk field)  then give output so I can delete it from tblwordtags.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Author Comment

by:PeterBaileyUk
ID: 41789289
L5EMW_T_6' was just an example. i am looking for orphaned codes as the tblword will get updated from time to time.
0
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41789293
This gives you all non existence words:
SELECT ClientCodeWordPosition 
FROM TblWordTags  
WHERE NOT EXISTS (SELECT 1 
              FROM tblWords 
              WHERE tblWords.ClientCodeWordPosition=TblWordTags.ClientCodeWordPosition)

Open in new window

and this is the DELETE command that you'll need:
DELETE
FROM TblWordTags  
WHERE NOT EXISTS (SELECT 1 
              FROM tblWords 
              WHERE tblWords.ClientCodeWordPosition=TblWordTags.ClientCodeWordPosition)

Open in new window

1
 

Author Closing Comment

by:PeterBaileyUk
ID: 41789297
i had made it more complicated and wrong too..thank you
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 41789303
KIS = Keep It Simple :)

Sometimes is better to drop all and start again taking another root.
Cheers.
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
McAfee ePO 5.3.1 failure to install 2 35
SQL Server Resume 5 44
Trigger C# code inside the SQL Server 6 24
Checking for column changes SQL 2014 4 15
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question