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 the highest record for a person w/ criteria

Author  Topic 

swims01
Yak Posting Veteran

59 Posts

Posted - 2009-05-01 : 16:45:37
Hey guys.

I'd like to select the highest record id for each individual person with criteria.

ex.

Select * from tbl where criteria

but it has to take into account the person's highest record.

ex data.

record, name, date
1, don, 1/1/2009
2, don, 1/1/2009
3, jack, 2/1/2009
4, don, 4/1/2009
5, jack, 4/5/2009

the select statement would return...
4, don, 4/1/2009
5, jack, 4/5/2009

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-01 : 16:54:49
SELECT record, name, MAX(date) as MaxDate
FROM tbl
GROUP BY record, name

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

swims01
Yak Posting Veteran

59 Posts

Posted - 2009-05-04 : 15:48:55
Tara -
Does that return results based on the max date or max record?

Edit* From that I was able to figure out the rest. Thanks, yet again, Tara =)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-04 : 16:58:46
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -