Union command returns the distinct values after combining the result-sets of the SELECT statements
Suppose you have two tables Table A and Table B as follows:
Table t1
Table t2
SELECT v1
FROM t1
UNION
SELECT v2
FROM t2;
If you run this above query, you will get the following output
Union All command return all the values (allows duplicate values) after combining the result-set of the SELECT statements.
SELECT v1
FROM t1
UNION ALL
SELECT v2
FROM t2;
If you run this query to join tables using UNION ALL, you will get the following output:
Compare both the results set for queries using UNION and UNION ALL operators. You can observe UNION returns only distinct values whereas UNION ALL allows duplicate values also.
You can go through SQL Interview Questions blog by Intellipaat to understand more about Union and Union All operators in SQL.