Oracle's various connections

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.