lundi 30 mars 2020

Mysql select random rows with multiple where conditions

This is my table example:

id     options     playlist_id
1      ...         7
3      ...         7
4      ...         9
11     ...         9
12     ...         7
14     ...         9

How do I select (for example) 3 random rows for each playlist_id and group results by playlist_id?

select id, options
from table
where playlist_id = 7 AND playlist_id = 9
group by playlist_id 
ORDER BY RAND()
LIMIT 3

I expect to return 3 random rows with playlist_id = 7 and 3 random rows with playlist_id = 9




Aucun commentaire:

Enregistrer un commentaire