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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL select question for selecting the most recent records

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-28 : 07:39:05
greg wright writes "I have a project im working on. There will be multiple records in the database for each individual with a column holding the date the record was entered. So, say i have 20 different individuals, each with at least 5 records. I want to be able to select only the most recent record for each of the 30 individuals and display them in a table.

Any help would be appreciated.

thanks
greg"

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-06-28 : 07:45:57
select userid, max(date) from table group by userid
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-06-28 : 08:40:17
.. which (in case it helps) leads to:

SELECT *
FROM MyTable T1
WHERE UserID = 'FRED'
AND MyDate =
(
SELECT MAX(MyDate)
FROM MyTable T2
WHERE T2.UserID = T1.UserID
)

Kristen
Go to Top of Page
   

- Advertisement -