Left joins, right joins, how are inner joins all handed?

Source: Internet
Author: User
Tags null null

1.left join literally, the left hand, is based on left table, and the right table is joined by the corresponding field's connection.

Table A

ID Name

1 sheets of three

2 John Doe

3 Harry

4 Xiao Chen

b table

ID Job

1 cooks

2 Teachers

3 workers

5 Engineer

SELECT * from a LEFT join B on a.id=b.id

The result is this:

ID Name ID Job

1 sheets of 31 cooks

2 Li 42 Teacher

3 Kings 53 workers

4 Xiao Chen null null

The left join is displayed in all, and the right table shows the fields and values that match, and the null display is not matched.

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

2.right Join

Right join literally, that is, to be handed, is based on the right table, and the left table is joined by the corresponding field connection.

Also take the example above:

SELECT * from a LEFT join B on a.id=b.id

The displayed results are conceivable:

ID Name ID Job

1 sheets of 31 cooks

2 Li 42 Teacher

3 Kings 53 workers

Null NULL 5 Engineer

Right joins are all displayed on the table, and the left table shows the fields and values that match, and the null display is not matched.

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

3.inner joins literally, that is, intra-intersection, within the link. The intra-intersection is performed by connecting an equality field.

Still take the above example as an example:

SELECT * from a Inner join B on a.id=b.id

The result is this:

ID Name ID Job

1 sheets of 31 cooks

2 Li 42 Teacher

3 Kings 53 workers

The inner join is not matched by the left and right tables, but by the equivalent fields to link the values to form the table.

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

In real-world applications, the inner join is much faster than the left join and right join, but the specific usage situation depends on the data requirements.

Left joins, right joins, how are inner joins all handed?

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.