I have the following 4 selects:
select english,type from table where type='brief' ORDER BY RAND() LIMIT 5;
select english,type from table where type='small' ORDER BY RAND() LIMIT 5;
select english,type from table where type='medium' ORDER BY RAND() LIMIT 5;
select english,type from table where type='large';
Rather then making multiple queries I would rather run this as one UNION – also seeing the output from all is in the same format.
I’ve tried the following but the RAND() doesn’t appear to work. There are about 10 options for each type but I keep seeing the same 5 rather then a random return:
select english,type from table where type='brief' LIMIT 5
UNION
select english,type from table where type='small' LIMIT 5
UNION
select english,type from table where type='medium' LIMIT 5
UNION
select english,type from table where type='large' ORDER BY type,RAND();
Any advise on how to run this UNION with a true random return?
thx
If you want to order by the entire union you need to enclose the union in another select like this: