Mysql --- difference and connection between left connection, right connection, and internal connection

Source: Internet
Author: User

Two existing tables

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

The second table is the girl table, which records the girl's name and ID.


First case: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Examples/examples + examples/nXvLnYwarFrsn6se08L3A + CjxwPr/J0tS/vMLH08PX88GsvdM8L3A + CjxwPjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140617/2014061708594921.jpg" alt = "\">

Diaosi is a tragedy. She does not have a spouse in the girl table, so gname and gname. other are both NULL. Gao fushuai must be surrounded by beautiful women, so there are multiple lines of records.

Case 2:The host asks all girls to come on stage and bring their spouse. In this case, no matter whether a girl or not has a spouse, the table is associated with the table of boys based on the table of girls.

You can use left join.


Xiaomei is also quite tragic. There is no spouse in the boys' table, so both bname and bname. other are NULL. As for the relationship between Xiao Jiao, Xiao Zhi, and Xiao Lin with Gao fushuai and Xiao Wang, there are also many lines.

Case 3:The host asks all male and female with spouse to come to the stage. This is the internal connection.


Boy left join girl on boy. other = girl. other: Find the boy that meets the condition in the girl table. other = girl. the combination of other rows and the corresponding rows in the boy table. The boy table does not add NULL to the matched rows in the girl table.

Relationship between left and right connections and internal connections:

The left and right connections can be converted to each other. The A left join B on condition is equivalent to the B left join A on condition.

The join A inner join B on condition is the intersection of the left join B on condition and the B right join A on condition.

Related Article

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.