MySQL internal connection, left join, right connection

Source: Internet
Author: User

INNER JOIN (INNER join) (a typical join operation, using a comparison operator like = or <>). Includes both equal and natural connections. Inner joins use comparison operators to match rows in two tables based on the values of the columns that are common to each table
Left join (left JOIN or left OUTER join) is the data in the table on the right-hand side is the datum, if the left table has data in the right table, otherwise the data in the right table showing the data in the table is empty
The right join is based on the data in the right table, and if the right table has data on the left table without data, the data in the left table of the data in the right table is displayed as empty.
Full joins (full join or fully OUTER join) complete external joins return all rows from the left and right tables. When a row does not have a matching row in another table, the selection list column for the other table contains a null value. If there are matching rows between the tables, the entire result set row contains the data values of the base table.
Here are a few examples to explain in detail
Two tables:
A (Id,name)
Data: (1, Zhang San) (2, John Doe) (3, Harry)
B (Id,name)
Data: (1, student) (2, teacher) (4, principal)

Internal connection results:
Select a.*,b.* from A inner join B on a.id=b.id;
1 31 students
2 Li 42 Teacher

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 Join 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

MySQL internal connection, left join, right connection

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.