2

I am using the following query to select 1 random record -

SELECT name FROM table WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM table ) ORDER BY id LIMIT 1

but it gives me the same set of records every time I call it. How do I get better random record?

1 Answer 1

4

Try this:

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

1 Comment

This will not perform well for large number of records.

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.