SQL Server Random Rows

Suppose we have a set of data with 5000 records, and we need to write a query that helps us every time we are required to fetch 50 Random rows from that table.
 
How will you do that ?
 

Answer : SQL Server and Oracle Random functions.
 
SQL Server
 
 SELECT *
 FROM ID_CITYMST
 ORDER BY RAND()
 LIMIT 50
 
Oracle
 
 SELECT *
 FROM
 (
 SELECT *
 FROM id_citymst
 ORDER BY
 dbms_random.value
 )
 WHERE rownum <= 6
Ebook Download
View all
SQL Jobs
Read by 0 people
Download Now!
Learn
View all