faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

183 of 199 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

how can i select random rows from a table?

Feb 24th, 2008 00:21
dman, ditoiu cristian, stuart gilbert, Ryan Parr, Arman Galstyan, http://www.ttnr.org


SELECT * FROM table_name ORDER BY RAND();

Found at http://www.mysql.com/doc/M/a/Mathematical_functions.html
    
use:

SELECT * FROM table_name ORDER BY RAND() limit 1;

if you only want one result not all of them.