It's really a picture to clarify the difference between all joins, but unfortunately I still can't understand it, maybe people are lazy, and then basically a left join is enough for me, so I didn't study it carefully, but the reality Or force me to figure it out, I simply do it myself, and finally understand the meaning of the picture, listen to me one by one.
First, let's create two tables, the first table is named kemu, and the second table is named score:
1. Left join
, as the name implies, is "left join". Table 1 is left connected to table 2, and the left is the main one, which means that table 1 is the main one, and the data in table 2 is associated. The result found shows all the data on the left, and then the right The data that intersects with the left is displayed. as follows:
select * from kemu left join score on kemu.id = score.id
Result set:
2. Right join
"Right join", Table 1 is right connected to Table 2, with the right as the main, indicating that Table 2 is the main, and the data of Table 1 is related to query, and all the data of Table 2 and the data of the intersection of Table 1 and Table 2 are found, as follows:
select * from kemu right join score on kemu.id = score.id
Result set:
3. Join
Join, in fact, is "inner join". It is written as join for the abbreviation. Two means one. Inner join means that the intersection of two tables is mainly. If there is no association, it will not be displayed additionally. This is used in many cases, as follows
select * from kemu join score on kemu.id = score.id
Result set:
The above is the difference between the three connections!