Join specific usage

1. Join syntax concept

Join can be divided into three categories according to the function:

Left join (left join) That is: take all the data in the left table, even if there is no corresponding data in the right table, the data in the left table will be taken out and returned

Right join (right join): Contrary to left join, take all the data of the right table.

Inner join (inner join, also called equi-join) is: take the common data in two tables, similar to the intersection in mathematics.

二.Left Join

语句:select * from TableA left join TableB on TableA.orderid=TableB.orderid

Result description: Take all the records in TableA and the records in TableB that match, if there is no matching data in TableB, it will return null, and the number of data sets returned is the number in TableA.

The returned result set is shown in the figure:

3. Inner Join

语句:select * from A  inner join B on A.orderid=B.orderid

Result description: inner join produces a set of data that matches both A and B

The returned result set is shown in the figure:

四.Right Join

语句:select * from A right join B on A.orderid=B.orderid

Result description: Take all the records in TableB and the records in TableA that match, if there is no matching data in TableA, it will return null, and the number of returned datasets is the number in TableB.

The returned result is as shown in the picture: hehe, if there is no ready-made picture, the picture will not be complete. I believe you will understand the returned data set.

 

Guess you like

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