This is an alternate UNION syntax with final ORDER BY .
This is what the union between the two choices looks like:
(SELECT ...) UNION (SELECT ...) ORDER BY ... LIMIT ...
And here is what the union between one choice is as follows:
(SELECT ...) ORDER BY ... LIMIT ...
Not applicable to subqueries at all.
This is not documented in MySQL, but is obvious from the grammar :
top_level_select_init: SELECT_SYM { Lex->sql_command= SQLCOM_SELECT; } select_init2 | '(' select_paren ')' union_opt ; union_select_init: SELECT_SYM select_init2 | '(' select_paren ')' union_opt ; ... union_opt: { $$= 0; } | union_list { $$= 1; } | union_order_or_limit { $$= 1; } ;
Eevee
source share