Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by rand()

Status
Not open for further replies.

anto

Technical User
Aug 2, 2000
7
0
0
IT
I'm trying to get a randomly selected set of rows from a select query. I'm trying something like 'select * from table_name where colum='xxxx' order by rand() limit 10' as outlined in the manual. Well the server refuse anything coming after the 'by'. Where I'm wrong?<br><br>thanks
 
ORDER BY RAND() only works in the beta version of MySQL 3.23.xx.<br><br>To get a random record in earlier versions of MySQL, you need to do a little more work: <br><br>SELECT id,field1,field2,field3,id*0+RAND() as rand_rows FROM your_table WHERE field1='whatever' ORDER BY rand_rows LIMIT 10&quot;;<br><br>(assuming your primary key is 'id')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top