The LEFT join returns records that include all records in the left table and the equivalent of the junction fields in the right table;
Right join returns records that include all records in the right table and the junction fields in the left table;
INNER JOIN (equivalent join) returns only rows that have the same join field in two tables.
We build two simple tables A and B,:
A:B:
1) leftjoin
We execute the SQL statement: SELECT * from A left join B on a.id = b.id;
The results are as follows:
Description: The left join is based on the records of Table A, a can be regarded as the right table, and B can be regarded as left table.
In other words, the records of the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example: a.ID = b.id).
The low-record of table B is null.
1) Rightjoin
We execute the SQL statement: SELECT * from A right join B on a.id = b.id;
The results are as follows:
Note : The rightjoin is based on the records of Table B, a can be regarded as the left table, B can be regarded as the right table, and then join is based on the table.
Based on the right table (B), a table of insufficient places is filled with null.
1)INNER JOIN
We execute the SQL statement: SELECT * from A inner join B on a.id = b.id;
The results are as follows:
Note : only a.id = b.ID records are shown here. This shows that inner join is not based on who, it only shows records that match the criteria.
The difference between a left join, right join, INNER join in an SQL statement