MySQL Learning: Left JOIN, right join, INNER join

Source: Internet
Author: User

Table A is as follows:

AID Anum
1 a20110111
2 a20110112
3 a20110113
4 a20110114
5 a20110115

Table B is as follows:

BID Bname
1 bName0111
2 bName0112
3 bName0113
4 bName0114
8 bName0118

One, left join ... on

MySQL statement:

SELECT * from a left JOIN b on a.aid = B.bid

The results are as follows:

AID Anum BID Bname
1 a20110111 1 bName0111
2 a20110112 2 bName0112
3 a20110113 3 bName0113
4 a20110114 4 bName0114
5 a20110115 Null Null

Description

A LEFT join is based on a record of a table, a can be viewed as the left-hand table, B can be viewed as the right table, and a left table is the Ieft join. In other words, the records in the left table (A) will all be represented, and the right table (B) will only display records for the compound search condition (in the example: A.aid = b.bid).

b tables where the records are insufficient are null.

Second, right join ... on

The MySQL statement is as follows:

SELECT * from a right JOIN b on a.aid = B.bid

The results are as follows:

AID Anum BID Bname
1 a20110111 1 bName0111
2 a20110112 2 bName0112
3 a20110113 3 bName0113
4 a20110114 4 bName0114
Null Null 8 bName0118

Description

Right join is the opposite of the result of the left join, this time based on the right-hand table (B), where a table is deficient with null padding.

Third, inner join ... on

The MySQL statement is as follows:

SELECT * from a INNER JOIN b on a.aid = B.bid

Equivalent to:

SELECT * from A, b WHERE a.aid = B.bid

The results are as follows:

AID Anum BID Bname
1 a20110111 1 bName0111
2 a20110112 2 bName0112
3 a20110113 3 bName0113
4 a20110114 4 bName0114

Description

The inner join is not based on who, it just shows the records that qualify.

The left JOIN operation is used in any Frome phrase.

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.