Intra-and outer-connection differences in Oracle

Source: Internet
Author: User

Table T_user1,t_user2,t_user3, each with id,name two columns

Id

Name

1

10A

2

20A

Id

Name

1

10B

3

30B

Id

Name

1

10C

4

40C

There are two types of connections: inner and outer connections.

A . Internal Connection

Internal connections, the most common equivalent connection, for example:

SELECT *
from T_user1,t_user2
WHERE t_user1.id = t_user2.id


Results

id

name

id

name

1

10A

1

10B

B. External Connection

The outer connection is divided into left outer connection, right outer connection and full outer connection.

1. left outer join outer JOIN or Ieft Join

The left OUTER join is the addition of unmatched data from the primary table on the basis of the equivalent connection, for example:

SELECT *
from T_user1
Left OUTER JOIN T_user2
on t_user1.id = t_user2.id

Oracle supports an alternative notation

SELECT *
from T_user1, T_user2
WHERE t_user1.id=t_user2.id (+)

Results:

Id

Name

Id

Name

1

10A

1

10B

2

20A

Three tables do left outer joins

SELECT *
from T_user1
Left OUTER JOIN T_user2
on T_user1.id=t_user2.id
Left OUTER JOIN T_user3
on T_user1.id=t_user3.id

Another form of Oracle support

SELECT *
from T_user1,t_user2,t_user3
WHERE t_user1.id=t_user2.id (+)
and T_user1.id=t_user3.id (+)

Results:

id

name

id

name

id

name

1

10A

1

10B

1

10C

2

20A

2. right outer connection outer JOIN

The right outer join is based on the equivalent connection and the mismatched data of the connected table is added.

SELECT *
from T_user1
Right OUTER JOIN T_user2
on T_user1.id=t_user2.id

Another way that Oracle supports

SELECT *
from T_user1,t_user2
WHERE t_user1.id (+) =t_user2.id

Results:

Id

Name

Id

Name

1

10A

1

10B

3

30B

3. full out -of-the-outer JOIN or complete join

A full outer join is a combination of unmatched data from the left and right tables on the basis of an equivalent join.

SELECT *
from T_user1
Full OUTER JOIN T_user2
on T_user1.id=t_user2.id

The equivalent of the whole outer join, the same table first left connected, and then right connected

SELECT t_user1.*,t_user2.*
from T_user1
Left OUTER JOIN T_user2
on t_user1.id = t_user2.id
UNION
SELECT t_user1.*,t_user2.*
from T_user2
Left OUTER JOIN T_user1
on t_user1.id = t_user2.id

Results:

Id

Name

Id

Name

1

10A

1

10B

2

20A

3

30B

So that's a lot to sum up. Later encountered again to write.

Intra-and outer-connection differences in Oracle

Related Article

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.