Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL seleziona casualmente ciascuna delle categorie

Se hai due categorie (come nella tua domanda), il modo più semplice in MySQL è usare union all :

(select * from t_shop where category = 1 order by rand() limit 5)
union all
(select * from t_shop where category = 2 order by rand() limit 5)