1
I use the query
SELECT * FROM mpbbolao WHERE eTIME1>=2 LIMIT 1
for example. To receive a query result I use LIMIT 1
. Is there any way I can randomize what that "1" result will be?
1
I use the query
SELECT * FROM mpbbolao WHERE eTIME1>=2 LIMIT 1
for example. To receive a query result I use LIMIT 1
. Is there any way I can randomize what that "1" result will be?
2
You can use a random ordering, so you will have your first result also random.
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 has been removed of this response in the OS.
1
Hello, I managed to solve, follow the solution:
SELECT * FROM mpbbolao WHERE eTIME1>=2 order by rand() LIMIT 1
"order by Rand()" makes the order random, so the first result will also be.
Browser other questions tagged sql random
You are not signed in. Login or sign up in order to post.
Had already settled, but thanks for complimenting! will definitely help others!
– Luan Devecchi