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

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

猜你喜欢

转载自www.cnblogs.com/ql70me/p/10342288.html
今日推荐