Page 1 of 1
randomize SELECT
Posted: Sun Jan 30, 2005 7:39 pm
by HormonX
Is there a way to select random rows from a db using MySQL query string ?
Greg
Posted: Sun Jan 30, 2005 8:51 pm
by scorphus
Although not most elegant/correct solution, this works:
Code: Select all
SELECT *, rand() AS rnd FROM test_table ORDER BY rnd LIMIT 1;
I hope this works for you.
-- Scorphus
Posted: Sun Jan 30, 2005 10:27 pm
by feyd
it doesn't require aliasing rand to anything, but can help if you'd like to know how they were selected. For example:
Code: Select all
SELECT * FROM table_name ORDER BY RAND()
typically works as well.
Posted: Mon Jan 31, 2005 1:02 am
by timvw
[to make sure codd wouldn't turn in his grave :p]
the returned rows from a query are per definition unordered/in a random order if there is not a order by clause in the query.