Home > Database > Mysql Tutorial > What are MySql self-join, outer join, inner join, left join and right join?

What are MySql self-join, outer join, inner join, left join and right join?

王林
Release: 2023-05-27 12:52:11
forward
1989 people have browsed it

1, self-connection

In the final analysis, multiple tables are data restricted by adding certain conditions to the same table. This is simple to understand. Why use "where a.age = a.num;" in such a complicated way? .

2, outer join

Outer join includes left join and right join. Just look at the left join and right join

3, left join

To put it simply, no matter what the final result is, the table on the left is all displayed, and the table on the right is displayed according to the conditions

4, right connection

No need for my introduction. In fact, it is that simple and does not need to be complicated to understand.

Specific practice

--创建 stu这个表格
 CREATE TABLE `stu_name` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
--创建stu_score
 CREATE TABLE `stu_name` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Copy after login

Insert data:

What are MySql self-join, outer join, inner join, left join and right join?

1, left join

What are MySql self-join, outer join, inner join, left join and right join?

From the screenshot above, we can see that all the data in the table on the left is displayed, and the data in the table on the right is displayed based on conditions.

2, right connection

What are MySql self-join, outer join, inner join, left join and right join?

We can also know from the above picture that actually all the tables on the right are displayed, but not all the coordinate tables Displayed

3, self-join

What are MySql self-join, outer join, inner join, left join and right join?

It can be seen from here that the same table is actually operated here, that is, self-join

4, Internal connection

What are MySql self-join, outer join, inner join, left join and right join?

The so-called internal connection is to display the same parts, and delete the other ones that do not meet the conditions!

The above is the detailed content of What are MySql self-join, outer join, inner join, left join and right join?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template