sql中的where子句

sql语句在很多场景下,需要使用where子句对sql操作进行筛选,提取出表数据的子集

比如在下面这张部门表为例

我们筛选部门编号为d002时的部门名称和部门编号那么语句为:

select dept_no,dept_name from departments where dept_no='d002';

又比如部门编号不为d002时的部门编号和部门名称,那么语句为:

select dept_no,dept_name from departments where dept_no !='d002';

等价与

select dept_no,dept_name from departments where dept_no  <>'d002';

     

再比如查询部门编号为d002到d005之间的部门编号和部门名称

select dept_no,dept_name from departments where dept_no  between 'd002' and 'd005';

where子句中null值检查时,则使用    字段 is null 或者  字段 is not null

null值是空值,空值null和字段包含0,空字符串以及空格不同

比如查询部门表中部门编号为null的部门编号和部门名称

select dept_no,dept_name from departments where dept_no  is  null ;

再比如查询部门表中部门编号不为null的部门编号和部门名称

select dept_no,dept_name from departments where dept_no  is not null ;

生于忧患,死于安乐
原文地址:https://www.cnblogs.com/songlove/p/15489883.html