Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Join/Subqueries: cannot find a simple solution
Message
 
À
07/07/2003 06:52:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00807382
Message ID:
00807416
Vues:
19
I know that Distinct will give you just one record per contact but I'm not 100% certain if its the first or the last of the results set. It might be worth giving it a try with your data and check the results.
HTH
Caroline


>I have two tables, say contact and note. I want to write a single query that works for SQL Server (and ideally for VFP with minimum changes). I want to return a single record for each contact, and the most recent note for that contact (if a note exists).
>
>I would pseudo code this as:
>
>
>SELECT * FROM contact LEFT JOIN (SELECT TOP 1 * FROM note ORDER BY date DESC WHERE contact.id = note.cid) ON contact.id = note.cid
>WHERE other_conditions
>
>
>OR
>
>
>SELECT *, MAX(note.date) FROM contact LEFT JOIN note ON contact.id = note.cid GROUP BY contact.id
>
>
>The second sort of works in VFP with engine behaviour in 7.0 mode. I cannot find any feasible method in SQL Server.
Caroline
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform