Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join Query-capture excluded data

Author  Topic 

eembme
Starting Member

18 Posts

Posted - 2007-09-26 : 14:11:46
I have 2 tables, table one with 772 pieces of compliant data. Table 2 has 435 pieces of data that meet another criteria (all the columns are identical it was just passes through an additional filter). I need to capture the values that are excluded from table 2.

Example Table 1
ID some value
1 x
2 x
3 x
4 x
5 x

Table 2
ID some value
2 x
3 x
5 x

I need to capture the data from ID 1 and 4 and assign a new value to it, it is extra compliant data. Thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-26 : 14:14:49
SELECT t1.ID, t1.SomeValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2 ON t2.ID = t1.ID
WHERE t2.ID IS NULL



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

eembme
Starting Member

18 Posts

Posted - 2007-09-26 : 14:45:29
Thanks so much! I was stuck on that.

My code is posted below in case any else has this problem

SELECT [all compliance].[Patient ID],[all compliance].Datetime
FROM [all compliance]
LEFT JOIN [filtered 2] ON [filtered 2].Datetime = [all compliance].Datetime
WHERE [filtered 2].Datetime IS NULL
ORDER BY [Patient ID], [Datetime]
Go to Top of Page
   

- Advertisement -