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:
01478675
Views:
23
>>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.

If you want to fix this code, Sergey meant here:


>>
SELECT * FROM ChildTable ct WHERE NOT EXISTS (SELECT 1 FROM ChildTable WHERE FK = ct.FK and SomeDate > ct.SomeDate)
use the field you need to aggregate on here to join, e.g. ClientID in your case.

Or, similar variation:
select * from ChildTable where PK = (select top 1 PK from ChildTable order by ModDate DESC)
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