ORDER BY

suggest change

If you need to sort the results of a UNION, use this pattern:

( SELECT ... )
UNION
( SELECT ... )
ORDER BY

A trailing ORDER BY sorts the whole UNION. Put parentheses around a branch when that branch has its own ORDER BY or LIMIT. Without them, MySQL rejects those clauses on the individual SELECTs.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents