There are lots of ways to select a random record or row from a database table. Here are some example SQL statements.
Select a random row with MySQL:
Syntax:
SELECT * FROM TABLE_NAME ORDER BY RAND() LIMIT 10;
Select a random row with Microsoft SQL Server:
Syntax:
SELECT TOP 1 column FROM table ORDER BY NEWID()
Select a random record with Oracle:
SELECT column FROM ( SELECT column FROM table ORDER BY dbms_random.value ) WHERE rownum = 1;
No comments:
Post a Comment