SQL to Select a Random Row

MySQL:[code=sql]SELECT column FROM table ORDER BY RAND() LIMIT 1[/code]
PostgreSQL:[code=sql]SELECT column FROM table ORDER BY RANDOM() LIMIT 1[/code]
Microsoft SQL Server:[code=sql]SELECT TOP 1 column FROM table ORDER BY NEWID() [/code]
IBM DB2:[code=sql]SELECT column FROM table ORDER BY RAND() FETCH FIRST 1 ROWS ONLY[/code]
Oracle:[code=sql]SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1[/code]

2 thoughts on “SQL to Select a Random Row

Leave a Reply

Your email address will not be published. Required fields are marked *