The Union and JOIN statements in SQL are very similar, but the union has a constraint: two SQL statements produce a field that needs to be the same type of data, and the final result will see a different data value.
Format:
[SQL Statement 1]
UNION
[SQL Statement 2]
For example:
Table Store_info
and table Internet_sales
Use the Union statement:
Copy Code code as follows:
SELECT Date from Store_info
UNION
SELECT Date from Internet_sales
Results:
Or:
Copy Code code as follows:
SELECT Date,sales from Store_info
UNION
SELECT Date,sales from Internet_sales
Results:
Finally, the union all and the Union are basically the same, except that the result is that it contains duplicate data.
Such as:
Copy Code code as follows:
SELECT Date from Store_info
UNION All
SELECT Date from Internet_sales
Results:
The above is the SQL statement of the Union and the use of union all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.