SQL UNION is used to combine the result sets of two or more SELECT Statements, provided they satisfy the below conditions:
Each SELECT statement within UNION should have the equal number of columns
The columns must also have similar data types
The columns in each SELECT statement must also be in the same order
UNION : KEYWORD used to combine the result set of both the tables
Difference between UNION AND UNION ALL
UNION removes duplicate rows.
UNION ALL does not remove duplicate rows.
Let’s consider a Demo Database with Table Individual and Address
Figure 37.1. Individual TABLE
Figure 37.2. Address TABLE
Figure 37.3. UNION OUTPUT
UNION ALL QUERY
Figure 37.4. UNION ALL OUTPUT
Want More SQL Deep Dives