Skip to content
Advertisement

How to request a random row in SQL?

How can I request a random row (or as close to truly random as is possible) in pure SQL?

Advertisement

Answer

See this post: SQL to Select a random row from a database table. It goes through methods for doing this in MySQL, PostgreSQL, Microsoft SQL Server, IBM DB2 and Oracle (the following is copied from that link):

Select a random row with MySQL:

Select a random row with PostgreSQL:

Select a random row with Microsoft SQL Server:

Select a random row with IBM DB2

Select a random record with Oracle:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement