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

First 10 records?

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
How to output first 10 records in 2000 record table... I'm confused because of mySQL LIMIT 10, access' TOP 10 and so on. Please help ASAP!
 
Code:
select foo, bar
  from yourtable xx
 where 10 >
       ( select count(*)
           from yourtable
          where foo > xx.foo )

here "foo" is the column that would be in the ORDER BY clause when you use LIMIT or TOP

in english, this query selects every row where 10 is greater than the number of rows that have a higher foo

caution: ties are included, so you might get 11

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top