I use the query
SELECT * FROM mpbbolao WHERE eTIME1>=2 LIMIT 1
for example. To get a query result I use LIMIT 1
. How can I randomize what this "1" result will be?
I use the query
SELECT * FROM mpbbolao WHERE eTIME1>=2 LIMIT 1
for example. To get a query result I use LIMIT 1
. How can I randomize what this "1" result will be?
You can use a random sort order, so you get your first random result as well.
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
MySQL Reference Manual: Mathematical Functions (RAND ())
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
PostgreSQL Documentation: Mathematical Functions and Operators
SELECT TOP 1 column FROM table
ORDER BY NEWID()
Microsoft Docs: NEWID () (Transact-SQL)
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
The code was taken from this answer in SO .
Hello, I was able to solve it, here is the solution:
SELECT * FROM mpbbolao WHERE eTIME1>=2 order by rand() LIMIT 1
"order by rand ()" causes the order to be random, so the first result will also be.