Difference and application of left and right outer connections

Source: Internet
Author: User
Tags null null
A (Id,name)
Data: (1, Zhang San) (2, John Doe) (3, Harry)
B (Id,name)
Data: (1, student) (2, teacher) (4, principal)

Left JOIN Connection results:
Select a.*,b.* from A left join B on A.id=b.id;
1 31 Students
2 Li 42 teacher
3 Harry NULL NULL

Right link result:
Select a.*,b.* from A right join B on a.id=b.id;
1 31 Students
2 Li 42 teacher
Null NULL 4 Principal

****************
Add: The following situation will be used outside the connection
For example, there are two tables, one is the user table, the other is the transaction table, if I want to query each user's transactions will need to use the left outer connection, because not every user has a transaction record.
After you use the left outer connection, the information for the transaction will be displayed, and nothing will show null, as I have shown in the example above.
If there is no external connection, such as "Harry" There is no transaction record, then the user table "Harry" information will not be displayed, lost the query all user transaction significance.
****************

Look at the results to understand the difference between the left and right connections.

Difference and application of left and right outer connections

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.