The purpose of the UNION all directive is to merge the results of the two SQL statements together. the union All and union differ in that union all lists each qualifying material, regardless of whether the data value is duplicated or not.
The syntax for UNION All is as follows:
[SQL Statement 1]
UNION All
[SQL statement 2];
We use the same example as the previous page to show the difference between union All and union . Also assume that we have the following two tables,
store_information Form
Store_name |
Sales |
Txn_date |
Los Angeles |
1500 |
05-jan-1999 |
San Diego |
250 |
07-jan-1999 |
Los Angeles |
300 |
08-jan-1999 |
Boston |
700 |
08-jan-1999 |
Internet Sales table
Txn_date |
Sales |
07-jan-1999 |
250 |
10-jan-1999 |
33s |
11-jan-1999 |
320 |
12-jan-1999 |
750 |
And we need to find out the days of store turnover and network turnover. To achieve this, we use the following SQL statement:
SELECT txn_date from Store_information
UNION All
SELECT txn_date from Internet_sales;
Results:
Txn_date |
jan-05-1999 |
jan-07-1999 |
jan-08-1999 |
jan-08-1999 |
jan-07-1999 |
jan-10-1999 |
jan-11-1999 |
jan-12-1999 |
Linux is measured as follows:
Reprint please specify: Xiao Liu
Linux SQL statement Concise tutorial---UNION all