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?

王林
王林forward
2023-05-27 12:52:111991browse

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

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete