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)
 Tough SQL Query (Solved)

Author  Topic 

Beast777
Starting Member

10 Posts

Posted - 2007-05-22 : 14:18:34
Right now I have added several records for two different people. I want to return the last date the person did the test, their name and the number of pushups they did. If my data was this

SN CheckDate Pushup
Sam 01/01/07 20
Sam 02/01/07 22
Ted 03/01/07 12
Sam 05/01/07 14
Ted 06/07/01 10


I would hope to get back this:

Sam 05/01/07 14
Ted 06/07/01 10

I am able to write this "SELECT SN, Max(CheckDate) as Expr1 from FitCheck group by SN" and that will give me the Name and Date but as soon as throw the Pushup into the mix, I am lost. Help please.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-22 : 14:22:15
[code]
select t1.*
from Table1 t1
join (select SN, max(CheckDate) as CheckDate
from Table1
group by SN) t2 on t1.SN = t2.SN
and t1.CheckDate = t2.CheckDate
[/code]

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Beast777
Starting Member

10 Posts

Posted - 2007-05-22 : 14:38:24
Amazing, that was fast, Thank you ever so much.
Go to Top of Page
   

- Advertisement -