Kamis, 27 Oktober 2011

[MS_AccessPros] Select TOP record per group

 

I have two tables that are joined. I would like to only have the record for the top begindate for each Contact show. I can't get it right. Here's what I have currently:

Two tables:
1. LookingEvent with LookingID, BeginDate, etc.
2. LookingContacts with LookingID, ContactID, etc

SELECT LookingEvent.LookingID, LookingContacts.ContactID, LookingEvent.BeginDate, LookingContacts.LookingID
FROM LookingEvent INNER JOIN LookingContacts ON LookingEvent.LookingID = LookingContacts.LookingID
WHERE LookingEvent.LookingID IN
(SELECT TOP 1 LookingContacts.LookingID
FROM LookingEvent As Dupe INNER JOIN LookingContacts AS Dupe2 ON Dupe.LookingID = Dupe2.LookingID
ORDER BY LookingContacts.ContactID, LookingEvent.BeginDate DESC);

Thanks!
Connie

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar