The difference between left join and right join, inner join and full outer join in SQL

left join (left join): Returns all records including all records in the left table and records with the same connection field in the right table.

right join (right join): Returns all records including all records in the right table and records with equal connection fields in the left table.

Inner join (equivalent connection or inner connection): Only return rows with equal connection fields in the two tables.

Full join (full outer join): Return all records in the left and right tables and records with the same connection fields in the left and right tables.

Table A:

id name
1 Xiao Wang
2 Xiao Li
3 Xiao Liu

 

Table B:

id A_id job
1 2 teacher
2 4 programmer

 

内连接:select a.name,b.job from A a inner join B b on a.id=b.A_id;

search result:

name job
Xiao Li teacher

 

左连接:select a.name,b.job from A a left join B b on a.id = b.A_id;

search result:

name job
Xiao Wang null
Xiao Li teacher
Xiao Liu null

右连接:select a.name,b.job from A a right join B b on a.id=b.A_id;

search result:

name job
Xiao Li teacher
null programmer

全外连接:select a.name,b.joib from A a full join B b on a.id=b.A_id;

search result:

name job
Xiao Wang null
Xiao Li teacher
Xiao Liu null
null programmer

 

Guess you like

Origin blog.csdn.net/Ally441/article/details/105020483