Test those things -SQL server merge using union query

Combining queries: two rows in a table into a single table to display

grammar:

select * from 表名1

union 

select * from 表名2

 

The combined features of the query:

The number of columns in claim 1. The combined combined query table.

2. Requests the column's data type must be the same or compatible, name of the column is determined by the first query column names.

3. The sum of the number of rows row query results to a lookup table, if there are duplicate rows will give it. If you want to display all of the data to be merged union all together

4 performed sequentially from top to bottom, the sequence may be used to change the space or column in the result set data location.

5. If you want to merge results into a new table in the display, then select into a query must be placed first.

select * from userinfo 

into newtable

union

select * from orderinfo

6. If you want to merge sort the table, it must be placed in order by the last query.

 

 Combining query and query connected difference:

Combining queries: row result set is determined by the first column in the table. The maximum number of rows and rows of two tables.

Join query: result set with columns from different tables. The maximum number of rows is their product.

Schematic:

The combined structure:

Connected structure:

 

Guess you like

Origin www.cnblogs.com/mgg520813/p/10932162.html