The usage of Union and Union All in SQL statements. The SQL statement unionall
In SQL, Union and Join statements are very similar, but Union has a condition that the columns produced by two SQL statements must be of the same data type, different data values are displayed in the final result.
Format:
[SQL statement 1]
UNION
[SQL statement 2]
For example:
Table store_info
And table internet_sales
Use the Union statement:
Copy codeThe Code is as follows: SELECT Date FROM Store_Info
UNION
SELECT Date FROM Internet_Sales
Result:
Or:
Copy codeThe Code is as follows: SELECT Date, Sales FROM Store_Info
UNION
SELECT Date, Sales FROM Internet_Sales
Result:
Finally, Union All and Union are basically the same. The difference is that their results contain duplicate data.
For example:
Copy codeThe Code is as follows: SELECT Date FROM Store_Info
UNION ALL
SELECT Date FROM Internet_Sales
Result:
The above is All about the usage of the Union and Union All statements in SQL statements. I hope you can give us a reference, and I hope you can provide more support to the customer center.