网站开发赚钱吗?,奇零seo赚钱培训,巩义网站推广,网站建设程序制作前言#xff1a; 业务开发时#xff0c;遇到的坑#xff0c;栽进去了#xff0c;写这个博客#xff0c;涨点记性 1.连表查询 左连接为例子 A left join B 把A的数据全部取出#xff0c;能够跟B对应的上#xff0c;B表的扩展数据也跟着展示出俩 A有B没有的#xff0c;B的… 前言 业务开发时遇到的坑栽进去了写这个博客涨点记性 1.连表查询 左连接为例子 A left join B 把A的数据全部取出能够跟B对应的上B表的扩展数据也跟着展示出俩 A有B没有的B的扩展字段也会展示为null
在on的后面加条件(连表的时候) 不管是 AND A.xx xxx 还是B.xxx xx 有时候发现根本不会生效 在on的后面加条件不管是A的还是B的返回的结果是什么都会先把主表数据先列出来 不要在on的后面加条件放在where 里面
记住一点就行查询条件不要放在连表 on 后面老老实实用where 就行
2.in 跟 not in ,! 数据: 1 null hhh 2 22 xxx 3 33 zzzz 使用in 自动忽略null的数据 select * from test where age in (22,33,null) 只能查出22,33的数据(预期是所有数据)
select * from test where age not in (33,null) 查询结果为空
使用not in 的时候如果not in 选项返回有null不会查询任何数据
查询1
select * from test where age not in (22,null)预期 3 33 zzzz 实际-无结果 null null null 查询2:
select * from test where age in (22,33,null)结果(预期是3条) 2 22 xxx 3 33 zzzz 查询3
select * from test where age ! 22预期结果 1 hhh 3 33 zzzz 实际结果 3 33 zzzz 需要预期结果的查询
select * from test where ( age ! 22 or age is null )
加括号是为了方便按其他条件筛选