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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting 3 table entries out of 5

Status
Not open for further replies.

Peter82

Technical User
May 10, 2008
5
ES
How can i select the first 3 data records out of a sorted tabel with for example 5 dara records
 

Select Top 3 col1, col2, col3, col4, ...
From table
Order By col1, col2, ... Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
I made a big mistake
How could i select 3 of each group in a table
 

Use a correlated sub query to select the top three by group and the outer query to select for all groups.

SELECT t1.groupid, t1.col2, t1.col3, ...
FROM table t1
WHERE t1.col2 IN
(SELECT TOP 3 t2.col2 FROM table t2
WHERE t2.groupid=t1.groupid)
ORDER BY t1.groupid, t1.col2;
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top