Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Random rows Expand / Collapse
Author
Message
Posted Wednesday, September 24, 2008 10:51 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 16, 2008 8:53 AM
Points: 22, Visits: 49

I need to select random 5% rows from 100 records. The Select Top (5) percent gives me the first 5 rows. I want a random 5% but not in order. Any suggestions ?
Post #575406
Posted Wednesday, September 24, 2008 11:00 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, April 07, 2014 4:50 PM
Points: 2,897, Visits: 5,966
Just select your top 5 percent rows and order by NEWID()

To help us help you read this

For better help with performance problems please read this
Post #575416
Posted Wednesday, September 24, 2008 11:09 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, March 15, 2014 4:31 AM
Points: 2,808, Visits: 7,173
Even easier use the TABLESAMPLE funciton in sql 2005

select   * from MyTable tablesample(5 percent)

there are some limitations on this though check BOL, the smaller the number of rows in your table the less accurate the % sample will be.

Post #575422
Posted Wednesday, September 24, 2008 11:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 16, 2008 8:53 AM
Points: 22, Visits: 49
thanks but this did not get 5%
Post #575433
Posted Wednesday, September 24, 2008 11:28 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 16, 2008 8:53 AM
Points: 22, Visits: 49
thanks..this worked
Post #575440
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse