目录
场景: 两种情况录入数据,一种有xxId有数据一种没有,然后列表关联查询时xxId没数据的就查不出了
一、case when
貌似不太好使,放弃了,欢迎大佬们提供成功案例!
二、UNION ALL
改造前:
select * from bb b left pp p where d.pid=p.id and b.del_flag = 0 and p.del_falg = 0
改造后:
select * from bb b left pp p where d.pid=p.id and b.del_flag = 0 UNION ALL select * from bb b left pp p where d.pid=p.id and b.del_flag = 0 and p.del_falg = 0