Simple use case of five ways to join (Inner join, Left join, Right join

1. Inner join

An inner join combines the columns of two tables (such as A and B) based on a join predicate to produce a new result table 
. The INNER JOIN keyword returns rows when there is at least one match in the tables. 
write picture description here 
Below is a simple use case 
write picture description here

The following is the running code and the result 
write picture description here

2. Left outer join

Left outer join The Left join keyword will return all rows from the left table, even if there are no matching rows in the right table. 
write picture description here 
Below is a simple case 
write picture description here

Below is the test case 
write picture description here

3. Right outer join

The right outer join keyword right join will return all rows from the right table, even if there are no matching rows in the left table. 
write picture description here 
Below is a simple case 
write picture description here

Below is the run and its result 
write picture description here

4. Full join

Full join keyword Full join, as long as there is a match in one of the tables, Full join will return rows 
write picture description here

The following is a simple case 
write picture description here 
and the following is the operation and the result 
write picture description here

Note that full join is not supported in mysql, but databases such as orcal do. 
If you want to use Full join in mysql, the following error will be reported. 
write picture description here 
Solution: Use both left and right joins 
The following is a simple examplewrite picture description here

5. Cross-connect

Cross-connection is generally used less, and cross-connection is also called Cartesian connection or cross-multiplication connection. If A and B are two sets, their cross-connection is A*B 
The following is a simple case 
write picture description here


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324686495&siteId=291194637