Syntax
- 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";
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.