Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT Distinct Query problem

Author  Topic 

sbb1979
Starting Member

1 Post

Posted - 2006-12-07 : 10:52:28
Hello,

I'm reasonably new to SQL.

I have a table of information about meetings with various people. In it, I have the person's name and the date/time of the meeting (simplified example).

I need to write a query that SELECTs only the most recent meeting for each person.

Any ideas would be greatly appreciated.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-07 : 11:11:56
SELECT *
FROM Meetings
INNER JOIN (SELECT PersonID, max(MeetingDate) AS MeetingDate
FROM Meetings
GROUP BY PersonID) Recent
ON Meetings.PersonID = Recent.PersonID AND Meetings.MeetingDate = Recent.MeetingDate
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-08 : 02:44:23
Similar topic http://sqlteam.com/forums/topic.asp?TOPIC_ID=76049

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -