Skip to content Skip to sidebar Skip to footer

Accessing Random Rows From Database Without Repetition

I have designed a quiz scenario using MySQL database as my backend. I have a total of 20 questions and I would want to display them in random order from the database. I have tried

Solution 1:

If the table contains duplicate records, use SELECT DISTINCT to filter them out.

SELECTDISTINCT *
FROM mst_que
ORDERBY RAND()

Solution 2:

The order by clausule needs column names or relative positions , not values or values. So. Try to add the RAND to the select and order by it. Try this:

SELECT *, RAND() as ordering
FROM mst_que
ORDERby ordering;

Post a Comment for "Accessing Random Rows From Database Without Repetition"