Full SQL join usage

Source: Internet
Author: User

Divided into 1. Inner join 2. Left join 3. Right join 4. left Outer Join

First, set the two tables we want to use.

Table A Table B

ID name ID class

1 IBM 1 C1

2 Sony 3 C3

3 BMW 4 C4

1 inner join: Select * from a inner join B on A. ID = B. ID

Table ID name class

1 IBM C1

3 BMW C3

By the way, the IDs of both tables exist and the combined tables of the two tables are obtained.

2 left join: Select * from a left join B on A. ID = B. ID

Table ID name class

1 IBM C1

2 Sony null

3 BMW C3

The result is that all records of a (table on the left of the Left statement) are obtained, and the records corresponding to table B must be completed if no records exist.

3 right join: Select * from a right join B on A. ID = B. ID

Table ID name class

1 IBM C1

3 BMW C3

4 null C4

Right (right) returns all records of B (table on the right side of the right statement). If the records of Table A do not exist, they must be completed.

4 full outer join: Select * from a full outer join B on A. ID = B. ID

Table ID name class

1 IBM C1

2 Sony null

3 BMW C3

4 null C4

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.