MySQL---The difference between the left connection, the right connection, and the inner link

Source: Internet
Author: User

Two sheets available

The first table is the boys ' table, which records the boys ' names and their spouses ' numbers.

The second table is the girl's Watch, which records the girl's name and her own number.



The first case: the host asked all the boys to come on stage and bring their spouse. At this point, regardless of whether the boy has a spouse to come to power, so is the boys table as the basis for the girls table

You can consider using the left connection


Cock Silk compared to the tragedy, in the girls table without his spouse, so gname and Gname.other are null. Gaofu certainly beautiful surrounded, so there are many lines of records.


The second case: the host invites all the girls to take the stage and bring their spouse. At this point, regardless of whether the girl has a spouse to come to power, so it is based on the female table as the benchmark boys table

You can consider using the left connection


Mei is also more tragic, there is no corresponding spouse in the boys table, so bname and Bname.other are null. As for Xiao Jiao, Xiao Zhi, Xiao Lin and Gaofu and Xiao Wang's relationship is more chaotic, there are many lines.


In the third case , the host invites all male and female students with a spouse to come to power, so that they can be connected.



Visible boy left Join girl on boy.other = Girl.other meaning: Found in girl table satisfies condition Boy.other = Girl.other rows are combined with the row in the Boy table, and the boy table does not have a matching row in the girl table to complement null.


The relationship between left and right connections and internal connections:

Left and right connections can be converted to each other. A LEFT JOIN B on condition equivalent to B left join A on condition

INNER JOIN a INNER JOIN B on condition is a LEFT join B on condition and b right join a on condition intersection.

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.