The difference between left join, right join and inner join in sql

  1. The difference between left join, right join and inner join of
      sql All records of the left table and records with equal join fields in [the]
      left table[]

For example :
Table A is as follows:
Table B is as follows:
1. The left join
sql statement is as follows:

SELECT * from A LEFT JOIN B ON A.A_age=B.B_age

The results are as follows:
Result description: left join is based on the records of table A, A can be regarded as the right table, and left join is based on the left table. Therefore, the records of the left table A will be displayed, while the right table B will only display the records that meet the search criteria (A.A_age=B.B_age). Insufficient records in table B are all NULL.

2. The right join
sql statement is as follows:

SELECT * from A RIGHT JOIN B ON A.A_age=B.B_age

The results are as follows:
Result description:
Through observation, we will find that the result of the left join is just the opposite, the right join is based on the right table (B), and the shortage of the A table is filled with NULL.

3. The inner join
sql statement is as follows:

SELECT * from A INNER JOIN B ON A.A_age=B.B_age

The results are as follows:
Result description:
Only the records matching A.A_age=B.B_age in the two tables are displayed here, which means that the inner join is not based on who, it only displays the records that meet the conditions.

Leave a Comment

Your email address will not be published. Required fields are marked *