Is there a way to select random rows from a db using MySQL query string ?
Greg
randomize SELECT
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Although not most elegant/correct solution, this works:
I hope this works for you.
-- Scorphus
Code: Select all
SELECT *, rand() AS rnd FROM test_table ORDER BY rnd LIMIT 1;-- Scorphus
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it doesn't require aliasing rand to anything, but can help if you'd like to know how they were selected. For example:typically works as well.
Code: Select all
SELECT * FROM table_name ORDER BY RAND()