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
 How can I get the first record of each group

Author  Topic 

sunnykj
Starting Member

29 Posts

Posted - 2006-02-19 : 20:36:15
Master,
How can I get the first record of each group which I had selected by "Group by".I try it but failed.3ks

"USE pubs
SELECT top 1 *
FROM titles
GROUP BY type
ORDER BY price"

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-19 : 20:44:23
[code]SELECT *
FROM titles t
WHERE title_id in (select top 1 title_id from titles x where x.type = t.type order by price)[/code]


----------------------------------
'KH'

Time is always against us
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-20 : 00:39:52
Also refer point 2
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx

Madhivanan

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

- Advertisement -