Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Join/Subqueries: cannot find a simple solution
Message
 
To
07/07/2003 06:52:56
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00807382
Message ID:
00807416
Views:
18
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
Previous
Reply
Map
View

Click here to load this message in the networking platform