Blorner

Tuesday, December 7, 2010

Select limited random values and order it

It is a query example how to select limited count of random values from a MySQL database table and make it in order:


SELECT * FROM
(SELECT * FROM table_name ORDER BY RAND() LIMIT 3) as selected_rows
ORDER BY column_name DESC;


Where:
"table_name" is the name of the table where the values are selected,
"selected_rows" is the name of the rows of the table "table_name" are selected,
"column_name" is the name of the column by which the values are ordered.

No comments:

Post a Comment

Art Works Expo