1.准备
CREATE DATABASE mahaiwuji;
USE mahaiwuji;
CREATE TABLE emp
(
empno INT PRIMARY KEY,
ename VARCHAR(10),
sal INT
) ENGINE = INNODB DEFAULT CHARSET = utf8;
INSERT INTO emp VALUES (1,'smith',2800);
INSERT INTO emp VALUES (2,'allen',NULL);
INSERT INTO emp VALUES (3,'ward',NULL);
INSERT INTO emp VALUES (4,'jones',1300);
INSERT INTO emp VALUES (5,'martin',NULL);
INSERT INTO emp VALUES (6,'blake',3000);
2.IS NULL
比较一个数据是否是NULL
-- 查找sal为NULL的数据
SELECT * FROM emp WHERE sal <=> NULL;
-- 等价于
SELECT * FROM emp WHERE sal IS NULL;
3.IS NOT NULL
比较一个数据是否不是NULL
-- 查找sal不为NULL的数据
SELECT * FROM emp WHERE sal IS NOT NULL;