测试必备的Mysql常用sql语句系列

https://www.cnblogs.com/poloyy/category/1683347.html

 

前言

  • is null是一个关键字来的,用于判断字段的值是否为空值(NULL)
  • 空值 ≠ 0,也 ≠ 空字符串"" 

 

语法格式

两种写法:

  1. 字段值为空
  2. 字段值不为空
IS NULL
IS NOT NULL

 

确定表里面的数据,方便后面的栗子做对比

 

空值查询的栗子

查询sex字段为空的记录

select * from yyTest where sex is null;

查询sex字段不为空的记录

select * from yyTest where sex is not null;

知识点

  • is null 是一个整体,不能用  = null 替代
  • is not null 同理,不能用  != null  或  <>  替代