Sunday, 27 January 2013

SQL Query to get random records from table

SQL Query to get random records from table

Following query is used to get random number of records from SQL table


SELECT TOP 5 *
  FROM [JukeBox].[dbo].[tbl_Debate]
 ORDER BY NEWID()


Following query is update with were clause


SELECT TOP 5 *
  FROM [JukeBox].[dbo].[tbl_Debate]
  where ID not in (21,5,6,20,11,12)
 ORDER BY NEWID()

No comments:

Post a Comment