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?

1 Answer 1

3

Have you tried something like this

SELECT *
FROM    (
            SELECT * 
            FROM table 
            LIMIT 50
        ) sub
ORDER BY RAND() 
Sign up to request clarification or add additional context in comments.

2 Comments

doesn't work. it says: "every derived table has to have its own alias"
oh I just needed to provide it an alias after the closing brace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.