Showing posts with label random. Show all posts
Showing posts with label random. 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) ;

how to retrieve random records from table

Hi,
I m doing slideshow application. fro that i m using Ms Sql 7.0 server.
Now i want to retrieve each time 10 different records order by date
(it is the column) from table out of 100 records.
Plz, help me for writing the sql query for this.

Quote:

Originally Posted by pritisarode

Hi,
I m doing slideshow application. fro that i m using Ms Sql 7.0 server.
Now i want to retrieve each time 10 different records order by date
(it is the column) from table out of 100 records.
Plz, help me for writing the sql query for this.


select top 10 * from table order by newid(), mydate