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) Link to comment https://forums.phpfreaks.com/topic/36761-random-rows/ 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(); Link to comment https://forums.phpfreaks.com/topic/36761-random-rows/#findComment-175331 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. Link to comment https://forums.phpfreaks.com/topic/36761-random-rows/#findComment-175448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.