[SQL Excavator] - Multi-table join: union

introduce:

In sql unionis an operator used to combine the result sets of two or more select statements. It combines the results of multiple queries into a single result set and automatically removes duplicate rows. Note that unionthe operation requires that the queries being combined return the same number and type of columns.

usage:

unionThe basic syntax of is as follows:

select_statement1
union
select_statement2;

Among them, select_statement1and select_statement2are two or more select statements whose results will be combined.

Example:

Suppose we have two tables, table1and table2, which have the same structure and both have nameand agecolumns. We can unionmerge their data using:

-- 从 table1 和 table2 表中选择 name 和 age 列,并合并结果集
select name, age from table1
union
select name, age from table2;

Note: If you want to keep all rows, including duplicates, you can use union allinstead of union. union allYou can read the introduction of the next article~

hair

Guess you like

Origin blog.csdn.net/qq_40249337/article/details/131968989