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!

How limit SQL to select first 10 records?

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
US
Hi, I'm testing SQL code, which returns several hundred thousand records. How do put a limit into the code to select say the first 10 records? Thanks, Dan.
 
I don't know what RDMS you're using but in DB2 you can do:

Select *
from Table1

Fetch first 10 rows only


Obviously, that will give you the first 10 rows.
 

Select Top 10 * From table

In SQL Server you can also use Rowcount.

Set Rowcount 10

Select * From table

--Reset rowcount
Set Rowcount 0 Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks for the tips. I'm working on an HP3000 using IMAGE\SQL. Unfortunately, none of those tips work with that flavor of SQL. I'll use ADO and set the MaxRecords property to 10. Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top