How to combine two Select statement using UNION in MySQL?

To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT:

(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);

Ref: https://stackoverflow.com/questions/1415328/combining-union-and-limit-operations-in-mysql-query

Tags:,

Add a Comment

Your email address will not be published. Required fields are marked *