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.
Author |
Topic |
tishri
Yak Posting Veteran
95 Posts |
Posted - 2007-08-30 : 06:47:31
|
[code]need help getting the resultID ID11 22 42 33 43 16 5Expected Result ...ID ID11 23 46 5all records that has no previous matches will be selected...[/code]TCC |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-30 : 07:08:53
|
[code]SELECT MAX(ID) AS ID, ID1FROM ( SELECT s1.ID, s1.ID1 FROM @Sample AS s1 LEFT JOIN @Sample AS s2 ON s2.ID = s1.ID1 WHERE s2.ID IS NULL UNION SELECT s1.ID, s1.ID1 FROM @Sample AS s1 WHERE s1.ID NOT IN (SELECT s2.ID1 FROM @Sample AS s2 WHERE s2.ID < s1.ID) ) AS dGROUP BY ID1[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
tishri
Yak Posting Veteran
95 Posts |
Posted - 2007-08-30 : 07:25:29
|
thanksTCC |
 |
|
|
|
|