The difference between a inner join, a left JOIN, a right join, and a full join in an SQL statement

Source: Internet
Author: User
Tags define null joins null null

Simply and clearly, connect to the inner and outer links.

Suppose there are two tables of A and B

Internal connection: Inner JOIN indicates that the record of the AB table is displayed, excluding the condition of the AB table .

There are three kinds of outer joins, that is, left OUTER joins, right connection, OUTER join, full OUTER join, the following is a simple parse. 1.A Left OUTER JOIN B indicates that the records of table A are displayed, and the result set that matches the condition of table B is displayed, and the null representation of the condition is not met. 2.A Right OUTER JOIN B indicates that the records of table B are displayed, showing the result set that matches the condition of table A, and non-conforming null representation. 3.A Full OUTER JOIN B indicates that the records of table A and B are displayed, and the non-qualifying null representation.

Instance:

[[email protected]] Sql>select * from A;

Number Name
---- ----------
1000 Sheets of three
2000 John Doe
3000 Harry

[[email protected]] Sql>select * from B;

Numbered items
---- ----------
1000 TV
2000 VCR
4000 Bicycles

[[email protected]] Sql>set NULL nulls-This is where I define NULL as a "null value" for display aspects.

[[email protected]] Sql>select a.*,b.* from a inner join B on a. Number =b. number;

Number Name Number product
---- ---------- ---- ----------
1000 31,000 TVs
2000 Li 42,000 VCR

[[email protected]] Sql>select a.*,b.* from a LEFT join B on a. Number =b. number;

Number Name Number product
---- ---------- ---- ----------
1000 31,000 TVs
2000 Li 42,000 VCR
3000 Wang value NULL

[[email protected]] Sql>select a.*,b.* from a right join B on a. Number =b. number;

Number Name Number product
---- ---------- ---- ----------
1000 31,000 TVs
2000 Li 42,000 VCR
NULL NULL value 4000 bike

[[email protected]] Sql>select a.*,b.* from a full join B on a. Number =b. number;

Number Name Number product
---- ---------- ---- ----------
1000 31,000 TVs
2000 Li 42,000 VCR
3000 Wang value NULL
NULL NULL value 4000 bike

---

The difference between a inner join, a left JOIN, a right join, and a full join in an SQL statement

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.