MySql中join,left join, right join解释
作者:互联网
join:左表和右表完全匹配(取交集),数据不确定
left join:左表完全取,右表不存在的数据,补null,数据大于等于左表
right join:右表完全取,左表不存在的数据,补null,数据大于等于右表
例
左表join_1
右表join_2
左表join_1的主键ID关联右表join_2
1、join操作结果:
SELECT j1.id jid_1, j1.name, j2.id jid_2, j2.age FROM join_1 j1 JOIN join_2 j2 ON j1.id = j2.join_id ORDER BY j2.join_id ASC
2、left join操作结果:
SELECT j1.id jid_1, j1.name, j2.id jid_2, j2.age FROM join_1 j1 LEFT JOIN join_2 j2 ON j1.id = j2.join_id ORDER BY j2.join_id ASC
3、right join操作结果:
SELECT j1.id jid_1, j1.name, j2.id jid_2, j2.age FROM join_1 j1 RIGHT JOIN join_2 j2 ON j1.id = j2.join_id ORDER BY j2.join_id ASC
数据量计算:
左表500条数据
右表1500条数据
最大和最小数据量
join(最小:0,最大:1500)
left join(最小:500,最大:1499)
right join (最小:1500,最大:1999)
标签:right,join,j1,j2,右表,左表,id,left 来源: https://blog.csdn.net/zhanjian2012/article/details/91550470