karldesign Posted February 2, 2007 Share Posted February 2, 2007 Hi all, I want to create a sql statement that returns the rows in a random order but will return all rows. It will never be more than 10 rows, so it shouldn't be too slow. I do want to loop this though, so the rows need to be unique each time. ie: I have rows 1-7 and I want to return them in a random order but don't duplicate (1, 5, 4, 2, 3, 7, 6 - is good 1, 2, 4, 6, 7, 7, 3 - is bad) Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 2, 2007 Share Posted February 2, 2007 Just use ORDER BY RAND() in your SQL statement: SELECT * FROM myTable ORDER BY RAND(); Quote Link to comment Share on other sites More sharing options...
fenway Posted February 2, 2007 Share Posted February 2, 2007 I guess if there aren't more than 10 records in the table, then sure... but if you're LIMITing it to 10, and there are hundreds/thousands of records, ORDER BY RAND() is crazy slow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.