Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The usage of left connection, right connection, inner connection and full connection in Mysql

Shulou Source: shulou.com Published: 2022-06-02 04:52:19 09月30日 Update

This article mainly explains the use of left connection, right connection, inner connection and full connection in Mysql. The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of left connection, right connection, inner connection and full connection in Mysql.

1. Basic definition

Left join (left join): returns records that include all records in the left table and records with equal join fields in the right table.

Right join (right join): returns records that include all records in the right table and records that are equal to the join fields in the left table.

Inner join (equivalent join or inner join): only rows with equal join fields in two tables are returned.

Full join (full external join): returns all records in the left and right table that are equal to the join fields in the left and right table.

Take a chestnut:

Form A, form B

IdnameidA_ idjob1 Xiao Wang 12 teachers 2 Xiao Li 24 programmers 3 Xiao Liu

Inner join: only rows that match between two tables can be displayed

Select a.name,b.job from An an innner join B b on a.id=b.A_id

Result: Mr. Xiao Li

Left join: the table on the left is unrestricted

Select a.name, b.job from An a left join B b on a.id=b.A_id

Result: Xiao Wang null

Miss Xiao Li

Xiao Liu null

Right join: the table on the right is unrestricted

Select a.name, b.job from An a right join B b on a.id=b.A_ia

Result: Mr. Xiao Li

Null programmer

Full connection: there are no restrictions on the left and right tables

Select a.name, b.job from An a full join B b on a.id=b.A_id

Result: Xiao Wang null

Miss Xiao Li

Xiao Liu null

Null programmer

Note: external and external connections in sql include: left connection, right connection, full connection.

Equivalent connection is also called inner connection.

Thank you for your reading, the above is the content of "left connection, right connection, inner connection and full connection in Mysql". After the study of this article, I believe you have a deeper understanding of the usage of left connection, right connection, inner connection and full connection in Mysql, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Whole company teacher Xiao Li fields results programs programmers Xiao Liu Xiao Wang learning restrictions content two also known as only on the right that is ideas situations articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn Linux Xiaomi NVidia