Question

I would be grateful if you could help me.

I would like to write a select statement which would do the following:

"Select a random ID from the 4 lowest ID in the same table"

Note: ID may be for example the score of students from a list of around 100 records in a table. I would like to get the 4 students with the lowest score and finally pick one record randomly.

Thanks lots

Was it helpful?

Solution

I find out about the following code:

SELECT * FROM (select * from tablename ORDER BY status ASC limit 4) q ORDER BY RAND() LIMIT 0,1;

Kindly confirmed whether it is a good answers and proper way to do the select. Any answers would be welcomes

thanks much

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top