The following is an example:
Example
Table
Aid adate
1 A1
2 A2
3 A3
Table B
Bid bdate
1 B1
2 B2
4 B4
Left join:
Select * from a left join B on A. Aid = B. Bid
First, retrieve all the data in Table A, and then add the data that matches table A and table B.
In this case, the following information is taken:
1 A1 B1
2 A2 B2
3 A3 null characters
Right join is also available.
This means that all data in Table B is retrieved first, and then the data matching A and B is added.
In this case, the following information is taken:
1 A1 B1
2 A2 B2
4 blank characters B4
Well, you must note that the left and right connections are connected to two tables A and B. The data of fields with the same ID must be retrieved,
Select * from a, B where a. Aid = B. Bid this is to retrieve only matching data.
In this case, the following information is taken:
1 A1 B1
2 A2 B2
By the way, union and Union all
Union is used to connect the data of two tables and exclude all duplicate data.
Union all does not exclude duplicate data.
Below is what you may be interested inArticle:
Usage Analysis of MySQL left join, right join, and inner join
SQL outer link Operation summary inner join left join right join
Left join right join in SQL