MySQL Unions
suggest changeSyntax
- SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
- SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2;
- SELECT column_name(s) FROM table1 WHERE col_name=“XYZ” UNION ALL SELECT column_name(s) FROM table2 WHERE col_name=“XYZ”;
Remarks
UNION DISTINCT
is the same as UNION
; it is slower than UNION ALL
because of a de-duplicating pass. A good practice is to always spell out DISTINCT
or ALL
, thereby signaling that you thought about which to do.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents