Never know what is the difference between Union and union all in the end, today to do a good research, the results of the online search is the following look, but still not very understanding, the following will personally verify:
Union: The two result sets are combined to set operations, excluding duplicate rows, while the default rules are sorted;
Union all: A set of two result sets, including duplicate rows, is not sorted;
The following is a simple test (because it is a test, so the SQL code is written very simply, there is no strict specification, just to understand the difference between the two)
Strict standard writing should first determine whether the database exists, whether the table exists and so on constraints
The first step is to build the library: View plain Create database test go with test go
Step two, build table: View plain CREATE TABLE Table1 (ID int not NULL, name varchar. NOT NULL) Create table Ta Ble2 (id int not NULL, name varchar NOT NULL)
The third step is to insert the test data:
View plain Insert into Table1 values (1,