samedi 11 septembre 2021

How to combine results of two select, UNION All, rand()

There is table, which contains some answers. One of answers is true (field tf=1), and several are false (field tf=0). How to select 1 true answer and N false random answers? The result must be in random order. This is my example, it works, but true answer always in first row:

(SELECT * FROM answers where tf=1 and `questionsid`=1 limit 1)
UNION all
(SELECT * FROM answers where tf=0 and `questionsid`=1 order by rand() limit 5 )



Aucun commentaire:

Enregistrer un commentaire