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

How do I select a specific number of records.

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I have a table that has about 18,000 records. Each record has a unique random number. I want to select 1000 records with the smallest random number, I am not sure how to go about doing this.
 

Depending on the version of SQL Server you run you can do one of the following.

Example 1: Use TOP Predicate
Select TOP 1000 col1, col2, col3, ...
From table
Order by randomkey desc

Example 2: Set maximum rowcount
Set rowcount 1000
Select col1, col2, col3, ...
From table
Order by randomkey desc
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top