Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting top occurrence of master table
Message
 
 
To
26/08/2010 12:50:51
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01478636
Message ID:
01478643
Views:
29
>I have a master table which contains some clients. For each clients, I need to locate the most recent records in the child table. I have done that a few times but cannot remember to cleanest way to do it.
;with cte as (select P.*, C.*, row_number() over (partition by P.ClientID order by C.Date DESC) as Row from Parent P inner join Child C
on P.ClientID = C.ClientID from myTable)

select * from cte where Row  =1
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform