A concise tutorial on SQL statements in linux --- UNION ALL, a concise tutorial --- union
UNION ALLThe purpose of this command is to combine the results of two SQL statements.UNION ALLAndUNIONThe difference is thatUNION ALLEach qualified item is listed, regardless of whether the item value is repeated.
UNION ALLSyntax:
[SQL statement 1]
UNION ALL
[SQL statement 2];
We use the same example on the previous page to showUNION ALLAndUNION. Let's assume that we have the following two tables,
Store_InformationTable
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 SalesTable
Txn_Date |
Sales |
07-Jan-1999 |
250 |
10-Jan 1999 |
535 |
11-Jan 1999 |
320 |
12-Jan 1999 |
750 |
However, we need to find out the days when there are store turnover and network turnover. To achieve this goal, we use the following SQL statement:
SELECT Txn_Date FROM Store_Information
UNION ALL
SELECT Txn_Date FROM Internet_Sales;
Result:
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 has been tested as follows:
Reprinted, please note: Xiao Liu
Bytes