SQL internal and external connection usage and differences

Source: Internet
Author: User


The data tables are connected with:

1. Inner connection (natural connection): only two rows matching the table can appear in the result set

2. External connection: including

(1) Left outer connection (the table on the left is unrestricted)

(2) Right outer connection (no restriction on the right table)

(3) Full-outer connection (no restriction on both the left and right tables)

3. Self-Connection (connection occurs within a base table)

Select A.studentno, A.studentname, B.classname

From students A, classes B

where A.CLASSID (+) = B.classid;

Studentno Studentnam CLASSNAME

---------- ---------- ------------------------------

1 A first Grade first class

2 B first Grade class two

Grade three class one year

The above statement is the right connection:

That is, the other side of the position of "(+)" is the direction of the connection, and the right connection describes all

Records are displayed regardless of whether they are matched on the left. That is to say, the above example, no

Will there be a class without a student's case, the class name will be in

Appears in the query structure.

Instead:

Select A.studentno, A.studentname, B.classname

From students A, classes B

where A.classid = B.classid (+);

Studentno Studentnam CLASSNAME

---------- ---------- ------------------------------

1 A first Grade first class

2 B first Grade class two

3 C

Is the left connection, whether or not the student has a department number that can be matched in a class,

The student's record will be displayed.

Select A.studentno, A.studentname, B.classname

From students A, classes B

where a.classid = B.classid;

This is the usual internal connection, showing that both tables meet the criteria of the record

Anyway

Left join to show the left and right side of the same

The right connection shows all the right and left and right

The inner connection is only displayed to meet the criteria!

SQL internal and external connection usage and differences

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.