I have a table whose structure and data inside it is as follows:
The table has an auto increment field named ‘id’. It has another field named ‘q_r_id’ which also stores id but here the id may be repeated (for e.g. id-12 may be repeated in more than 1 row but max 5 rows) .
I want to select fixed number of records from this table RANDOMLY but ensuring that from ‘q_r_id’ field if for example id-12 is chosen then all the rows(i.e all the five rows of id-12 should be included in the random result .
I am using the following query but not getting desired result:
SELECT * FROM tblreasoningip_r WHERE id >= (SELECT FLOOR(MAX(id)*RAND()) FROM tblreasoningip_r)
group BY q_r_id LIMIT 0,30
Any help would be highly appreciated.
Aucun commentaire:
Enregistrer un commentaire