Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi..I have the following records1 20002 20001 2001How do I select the second record?..that is the account that have NO equivalent in the next year(2001)Thanks
Onamuji
Aged Yak Warrior
504 Posts
Posted - 2001-12-19 : 09:02:55
SELECT t1.f1, t1.f2FROM (SELECT 1 f1, 2000 f2 UNION SELECT 2, 2000 UNION SELECT 1, 2001) t1 RIGHT JOIN (SELECT 1 f1, 2000 f2 UNION SELECT 2, 2000 UNION SELECT 1, 2001) t2 ON t1.f1 > t2.f1 AND t1.f2 = t2.f2WHERE t1.f1 IS NOT NULL AND t1.f2 IS NOT NULL