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 2008 Forums
 Transact-SQL (2008)
 How to display id top 1 in the select for each gro

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-04-10 : 02:14:32
I have unique data select

select [text],[start_date],[end_date],[room_id]
from Events
group by [text],[start_date],[end_date],[room_id]

I just need to display id top 1 in the select for each group by item, how can i do it?

I try this, the data duplicate again due to difference on id

select [id],[text],[start_date],[end_date],[room_id]
from Events
group by [id],[text],[start_date],[end_date],[room_id]

micnie_2020
Posting Yak Master

232 Posts

Posted - 2012-04-10 : 02:59:14
I got the answer using Max & Group By.

Thank You.
Go to Top of Page
   

- Advertisement -