The secret to retrieve random rows from database is really simple. Here are some example SQL statements that do not require additional application logic.
SQL Server:
SELECT TOP 1 *
FROM Users
ORDER BY NEWID()
MySQL:
SELECT * FROM Users
ORDER BY RAND()
LIMIT 1;
Oracle:
SELECT * FROM
(SELECT * FROM Users
ORDER BY dbms_random.value )
WHERE rownum = 1
PostgreSQL:
SELECT * FROM Users
ORDER BY RANDOM()
LIMIT 1
Access:
SELECT TOP 1 *
FROM Users
ORDER BY Rnd(UserID)
Cheers!
SQL Server:
SELECT TOP 1 *
FROM Users
ORDER BY NEWID()
MySQL:
SELECT * FROM Users
ORDER BY RAND()
LIMIT 1;
Oracle:
SELECT * FROM
(SELECT * FROM Users
ORDER BY dbms_random.value )
WHERE rownum = 1
PostgreSQL:
SELECT * FROM Users
ORDER BY RANDOM()
LIMIT 1
Access:
SELECT TOP 1 *
FROM Users
ORDER BY Rnd(UserID)
Cheers!