Sometimes we need to select random records from a table in our database. For example, if you created online test application then every time we need to get the random questions from our questions table.
Today I will give you some examples for selecting random records in some popular databases.
Select random rows in MySQL
SELECT column FROM table
ORDER BY RAND()
LIMIT 10
Select random rows in Oracle
SELECT column FROM ( SELECT column FROM table ORDER BY dbms_random.value ) WHERE rownum <= 10
Select random rows in Microsoft SQL Server
|
No comments:
Post a Comment