Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting top occurrence of master table
Message
 
 
À
26/08/2010 12:58:38
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01478636
Message ID:
01478675
Vues:
24
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform