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
 Transact-SQL (2000)
 Select Max....

Author  Topic 

jon_bulalaque
Starting Member

2 Posts

Posted - 2005-08-29 : 05:09:43
hi, i have a subquery that returns this result

Team_ID User_ID LoggedHrs
1 2 180
3 2 180
1 4 6040
4 4 6040
5 4 6040

what i wanted to do now is select the max loggedhrs for the team_id and the user_id who logged that hrs.

thanks in advance...

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-29 : 05:14:11
Select Team_Id,User_Id,Max(LoggedHrs) from yourTable group by Team_Id,User_Id

Madhivanan

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

jon_bulalaque
Starting Member

2 Posts

Posted - 2005-08-30 : 01:44:08
thanks for the reply... i tried that one but it would result to

Team_ID User_ID LoggedHrs
1 4 6040
4 4 6040
5 4 6040
1 2 180
3 2 180

what i'm expecting is

Team_ID User_ID LoggedHrs
1 4 6040
4 4 6040
5 4 6040
3 2 180
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-30 : 01:55:48
Try this

Select max(Team_Id),User_Id,Max(LoggedHrs) from yourTable group by Team_Id,User_Id


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-30 : 02:14:30
If the above does not work, this should work


Select distinct team_id,(select max(user_id) from yourTable where Team_id=T.team_id),
(select max(LoggedHrs ) from yourTable where Team_id=T.team_id) from yourTable T

Madhivanan

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

- Advertisement -