vendredi 11 septembre 2015

Return SQL SELECT query equals number of rows

I have a query:

SELECT * FROM TABLE_NAME 
WHERE category=1 AND NUMBER=4 OR NUMBER=10 
ORDER BY RANDOM() LIMIT 10

I want to receive the result of this query a randomly five lines whose category=1 and number=4, and also a randomly five rows in which the category=1 and the number=10. So it should be equal (!) number of rows that are specified in the WHERE after AND (five results with a number = 4, and five results with number=10). If, for example, change LIMIT 10 to LIMIT 20, it must be 10 lines with first result and 10 lines with second result. If I run written by me query it produces randomly, for example, 7 rows with number=4, and 3 lines with number=10.

Is it possible to implement this, or tell me what I can use to achieve such a result?

Aucun commentaire:

Enregistrer un commentaire