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:
01478651
Vues:
32
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform