How to get a random row or multiple random rows from a table ?
--#SQL to get a single random row from a table.
select top 1 column1, column2, column3 from tableName order by newid()
To get multiple random rows from a table, you need to just change the 'top' count.
--#SQL to get 10 random rows from a table.
select top 10 column1, column2, column3 from tableName order by newid()
Thursday, May 29
How to select random rows from a table
Labels:
SQL Tricks
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment