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 2000 Forums
 SQL Server Development (2000)
 QUERY HELP PLEASE

Author  Topic 

Da_Retina
Posting Yak Master

109 Posts

Posted - 2001-12-19 : 08:34:38
Hi..
I have the following records
1 2000
2 2000
1 2001

How 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.f2
FROM
(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.f2
WHERE
t1.f1 IS NOT NULL AND t1.f2 IS NOT NULL


Edited by - onamuji on 12/19/2001 09:04:01
Go to Top of Page
   

- Advertisement -