tags:

views:

31

answers:

1

When I write 'SELECT * FROM table ORDER BY RAND() LIMIT 50' mysql has to randomize the entire table then only fetch 50. What I want to do (in mysql, preferably not in php) is to fetch 50 rows THEN randomize them.

Is there a way to do this in Mysql?

+3  A: 

Have you tried something like this

SELECT *
FROM    (
      SELECT * 
      FROM table 
      LIMIT 50
     ) sub
ORDER BY RAND()
astander
doesn't work. it says: "every derived table has to have its own alias"
sombe
add an alias to the table, see the edit
astander
oh I just needed to provide it an alias after the closing brace.
sombe