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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Comparing two tables

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-09-26 : 08:56:13
I want to compare the PAN field from the current week file (NewDiary) to last week file to determined if the case is cleared.

Is this correct? Confused which table is listed first as I get different results from them both.

SELECT *
FROM NewDiary
WHERE PAN NOT IN (SELECT PAN
FROM Lastweekdiary
WHERE PAN = PAN)
ORDER BY LName

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 09:04:30
[code]SELECT nd.*
FROM NewDiary AS nd
LEFT JOIN LastWeekDiary AS lwd ON lwd.Pan = nd.Pan
WHERE lwd.Pan IS NULL
ORDER BY nd.LName[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 09:05:02
[code]SELECT nd.*
FROM NewDiary AS nd
WHERE NOT EXISTS (SELECT * FROM LastWeekDiary AS lwd WHERE lwd.Pan = nd.Pan)
ORDER BY nd.LName[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-09-26 : 09:11:41
Thanks!
Go to Top of Page
   

- Advertisement -