Hi all,
I am trying to fetch 5 records, randomly picked and in random order
from a MySQL table (MySQL version > 3.23).
I wrote my SQL Query as
SELECT name,id FROM tablename WHERE active = 'Y' ORDER BY RAND() LIMIT
5
But its not working. It returns records in a fixed order every time.
Can anybody suggest why its not working the expected way?
I found an alternative solution and used the following query
SELECT name,id FROM tablename WHERE active = 'Y' ORDER BY MD5(RAND())
LIMIT 5
Its working fine :-)
But still i am not clear why the first query is failing? :-(
Thanks in advance.
-- Rahul
I am trying to fetch 5 records, randomly picked and in random order
from a MySQL table (MySQL version > 3.23).
I wrote my SQL Query as
SELECT name,id FROM tablename WHERE active = 'Y' ORDER BY RAND() LIMIT
5
But its not working. It returns records in a fixed order every time.
Can anybody suggest why its not working the expected way?
I found an alternative solution and used the following query
SELECT name,id FROM tablename WHERE active = 'Y' ORDER BY MD5(RAND())
LIMIT 5
Its working fine :-)
But still i am not clear why the first query is failing? :-(
Thanks in advance.
-- Rahul
Comment