“查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )”
——翻译为:课程表里面,存在01的信息,未必满足有02的课程情况
——觉得题意不是很明确,但是就当成练习left join 和right join的理解
1、存在01课程情况
select * from sc where sc.cid='01'
2、存在02课程情况
select * from sc where sc.cid='02'
3、满足存在01,但是未必存在——满足01方向结果,未必满足02方向结果
select * from (select * from sc where sc.cid='01')as t1 left join (select * from sc where sc.cid='02')as t2 on t1.sid=t2.sid
3.1对比,满足02,未必满足01方向结果:
select * from (select * from sc where sc.cid='02')as t1 left join (select * from sc where sc.cid='01')as t2 on t1.sid=t2.sid
【既left join ,满足左边条件,右边可能为空】
【既right join ,满足右边条件,左边可能为空】
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!