SQL UNION operator
The UNION operator is used to combine the result set of two or more SELECT statements.
Note that the SELECT statement inside the UNION must have the same number of columns. The column must also have a similar data type. Also, the order of the columns in each SELECT statement must be the same.
SQL UNION Syntax
SELECT column_name (s) from table_name1
UNION
SELECT column_name (s) from table_name2
Note: By default, the UNION operator chooses a different value. If duplicate values are allowed, use UNION all.
SQL UNION All syntax
SELECT column_name (s) from table_name1
UNION All
SELECT column_name (s) from table_name2
In addition, the column name in the union result set is always equal to the column name in the first SELECT statement in the Union.
Another connection: inner and outer connections
To put it simply, here's an example:
A table B
ID Name ID Name
1 a 1 b
2 B 3 C
4 C
The inner connection is the same data as the left table and right table:
SELECT * FROM A inner join B on A.id=b.id
ID Name ID Name
1 a 1 b
Outer joins: Left outer connection, right outer connection, full outer connection
Left outer connection is to left table, to match the right table, the left table has how many data, the result is how many data
SELECT * from A LEFT join B on A.id=b.id
ID Name ID Name
1 a 1 b
2 b NULL NULL
4 c NULL NULL
The right outer connection is connected with the left outer connection, in contrast, to the right table, to match the left table, the right table has how many data, the result is how many data
SELECT * from A right join B on A.id=b.id
ID Name ID Name
1 a 1 b
NULL NULL 3 C
Total outer JOIN Data bar number is not necessarily, quite with is the left outer connection and the right outer joins the synthesis
SELECT * from A full join B on A.id=b.id
ID Name ID Name
1 a 1 b
2 b NULL NULL
NULL NULL 3 C
4 c NULL NULL
Oracle's various connections