Solved

sql server query

Posted on 2016-09-08
7
22 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 45

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 45

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 45

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 Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQl help with selection 14 44
how to fix this error 14 46
combine an MS SQL string in Idera DM 9 28
Mssql SQL query 14 26
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

708 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

16 Experts available now in Live!

Get 1:1 Help Now