Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group By
Message
 
 
To
21/04/2009 09:42:25
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01395684
Message ID:
01395749
Views:
76
You're welcome.

>Thanks Sergey. Your first example worked well in my situation.
>
>>There're many ways to get such result. Pick one that is most efficient for your data
>>
>>* 1
>>SELECT * FROM mytable mt1 
>>  WHERE StartDate = (SELECT MAX(StartDate) FROM mytable mt2 where mt2.fk = mt1.fk)
>>
>>* 2
>>SELECT * FROM mytable mt1 
>>  JOIN (SELECT fk, MAX(StartDate) AS MaxStartDate FROM mytable GROUP BY fk) dt1
>>    ON dt1.fk = mt1.fk AND dt1.MaxStartDate = mt1.StartDate 
>>
>>* 3
>>SELECT * FROM mytable mt1 
>>  WHERE NOT EXISTS (SELECT 1 FROM mytable mt2 where mt2.fk = mt1.fk AND mt2.StartDate > mt1.StartDate)
>>
>>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform