Divided into 1. Inner join 2. Left join 3. Right join 4. left Outer Join
First, set the two tables we want to use.
Table A Table B
ID name ID class
1 IBM 1 C1
2 Sony 3 C3
3 BMW 4 C4
1 inner join: Select * from a inner join B on A. ID = B. ID
Table ID name class
1 IBM C1
3 BMW C3
By the way, the IDs of both tables exist and the combined tables of the two tables are obtained.
2 left join: Select * from a left join B on A. ID = B. ID
Table ID name class
1 IBM C1
2 Sony null
3 BMW C3
The result is that all records of a (table on the left of the Left statement) are obtained, and the records corresponding to table B must be completed if no records exist.
3 right join: Select * from a right join B on A. ID = B. ID
Table ID name class
1 IBM C1
3 BMW C3
4 null C4
Right (right) returns all records of B (table on the right side of the right statement). If the records of Table A do not exist, they must be completed.
4 full outer join: Select * from a full outer join B on A. ID = B. ID
Table ID name class
1 IBM C1
2 Sony null
3 BMW C3
4 null C4