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 2005 Forums
 Transact-SQL (2005)
 group by clause problem

Author  Topic 

pacerier
Starting Member

5 Posts

Posted - 2010-08-06 : 07:01:33
i have select*from clientusername

Id Client UserName DateCreated
1 1 new 1 2010-08-06 10:11:37.200
2 1 new 11 2010-08-06 10:11:37.200
3 1 new 111 2010-08-06 10:11:37.200
4 2 new 2 2010-08-06 10:11:37.200
5 3 new 3 2010-08-06 10:11:37.200



and if i do: select max(datecreated)from clientusername group by client
i get the rows i needed:
2010-08-06 10:11:37.200
2010-08-06 10:11:37.200
2010-08-06 10:11:37.200


however the problem is that i will need the UserName column to show as well. right now the query is showing only the DateColumn of rows 3,4,5 but i need it to show the UserName column of rows 3,4,5

---

Sachin.Nand

2937 Posts

Posted - 2010-08-06 : 07:32:30
[code]
select * from(
select *,row_number()over(partition by Client order by id desc)as rid from yourtable
)t where rid=1
[/code]



Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

pacerier
Starting Member

5 Posts

Posted - 2010-08-06 : 11:29:04
hey thanks for the reply=)

---
Go to Top of Page
   

- Advertisement -