大家好,又见面了,我是你们的朋友全栈君。
举个例子:
A表
id name
1 小王
2 小李
3 小刘
B表
id A_id job
1 2 老师
2 4 程序员
内连接:(只有2张表匹配的行才能显示)
select a.name,b.job from A a inner join B b on a.id=b.A_id
只能得到一条记录
小李 老师
左连接:(左边的表不加限制)
select a.name,b.job from A a left join B b on a.id=b.A_id
三条记录
小王 null
小李 老师
小刘 null
右连接:(右边的表不加限制)
select a.name,b.job from A a right join B b on a.id=b.A_id
两条记录
小李 老师
null 程序员
全外连接:(左右2张表都不加限制)
select a.name,b.job from A a full join B b on a.id=b.A_id
四条数据
小王 null
小李 老师
小刘 null
null 程序员
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/141976.html原文链接:https://javaforall.cn