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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.