Showing posts with label randomly. Show all posts
Showing posts with label randomly. Show all posts

Wednesday, March 7, 2012

how to retrieve random values from a database table

how to retrieve randomly rows from a sqlserver database tableHi,

Use TABLESAMPLE

Example.

SELECT FirstName, LastName
FROM Person.Contact
TABLESAMPLE (10 PERCENT) ;

OR

SELECT FirstName, LastName
FROM Person.Contact
TABLESAMPLE (10 ROWS) ;

Friday, February 24, 2012

How to retrieve data randomly?

I have a table called Questions and I need to retrieve 10 rows of data randomly each time. If I use
SELECT TOP 10 Question FROM Questions
I'll get the same questions each time when I execute the sql statement. Is there a way to get the random data? Thanks.SELECT TOP 10 Question FROM Questions ORDER BY NEWID()