Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting top occurrence of master table
Message
 
 
To
26/08/2010 12:58:38
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01478636
Message ID:
01478651
Views:
31
>>This should get you started
>>
>>SELECT * FROM ChildTable ct WHERE NOT EXISTS (SELECT 1 FROM ChildTable WHERE pk = ct.pk and SomeDate > ct.SomeDate)
>>
>
>Thanks, but this returns all records from the child table.

Michel,

Why not take a moment to read the links I gave you to? They are really comprehensive (the first one especially) and show you and explain all various techniques of solving this problem.

And just in case another solution for you:
select P.*, C.*
from parent P
cross apply
(select top 1 * from Child where Child.ClientID = P.ClientID order by ModDate DESC) C
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform