当前位置: 移动技术网 > IT编程>数据库>Mysql > 小菜菜mysql练习解读分析2——查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )

小菜菜mysql练习解读分析2——查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )

2019年02月01日  | 移动技术网IT编程  | 我要评论

“查询存在" 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 ,满足右边条件,左边可能为空】

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网