Solved

sql server query

Posted on 2016-09-08
7
29 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 46

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 46

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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 …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now