Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping records

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
US
Hi,

Is there a way in the group by clause to group records into max of three records?

i.e. there may be more than 3 records belonging to that group in the query but I only want to see the top 3.

James.
 
select * from t q
where pkColumn in
(select top 3 pkColumn from t
where groupingColumn = q.groupingColumnd
order by orderColumn )

If that's not what you are looking for, could you be somewhat more specific. I.e. supply some sample data and the expected result.
 
Thanks,

this is exactly what i was looking for

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top