I am trying to combine these 3 mysql statements. I use UNION and JOIN Keyword, but it is not suitable for the output that I wanted. Any suggestions? These are my 3 statements.
SELECT * FROM entrancequestion
WHERE Subject='Abstract Reasoning'
ORDER BY RAND()
LIMIT 10
SELECT * FROM entrancequestion
WHERE Subject='English'
ORDER BY RAND()
LIMIT 30
SELECT * FROM entrancequestion
WHERE Subject='Mathematics'
ORDER BY RAND()
LIMIT 30
SELECT * FROM entrancequestion
WHERE Subject='Science'
ORDER BY RAND()
LIMIT 30
I tried to combine the first two operators like this:
SELECT * FROM entrancequestion
WHERE Subject='Abstract Reasoning'
LIMIT 10
UNION
SELECT * FROM entrancequestion
WHERE Subject='English'
ORDER BY RAND()
LIMIT 30;
however, it only reads the second LIMIT request, in which t prints only 30 lines.
I would like to create a query that displays a total of 100 rows and is randomized according to the index. Your help would be greatly appreciated.
source
share