Database-the difference between an inner connection and an outer join (illustration)

Source: Internet
Author: User
Tags joins

Inner joins, also known as natural joins, only two tables match the rows to appear in the result set. The returned result set selects all matching data from two tables, discarding unmatched data. Because an inner join removes all rows from the result table that do not match the other connection tables, the internal connection may cause information loss. The inner JOIN syntax is as follows:

Select FieldList from table1 [inner] join table2 on table1.column = Table2.column

An inner connection is a guarantee that all rows in two tables meet the conditions of the connection, but not the outer connection.

Outer joins contain not only rows that meet the join criteria, but also all data rows in the left table (when left connected), the right table (when connected right), or two edge tables (full outer joins). There are three types of out-of-SQL connections: Left OUTER join (the keyword is a OUTER join), a right outer join (the keyword is a OUTER join), and a full outer join (the keyword is an OUTER join). The use of outer joins is the same as an inner join, except that the INNER JOIN keyword is replaced with the corresponding outer join keyword.


An inner join displays only records that meet the join criteria, and the outer join displays records in the table, in addition to the records that match the criteria, for example, if you use a left outer join, the records in the left table are also displayed.


Example: Below is student table A and student table B:

The results of the inner and left outer joins of table A and table B are as follows:


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.