1.準(zhǔn)備
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
比較一個(gè)數(shù)據(jù)是否是NULL
-- 查找sal為NULL的數(shù)據(jù)
SELECT * FROM emp WHERE sal <=> NULL;
-- 等價(jià)于
SELECT * FROM emp WHERE sal IS NULL;
3.IS NOT NULL
比較一個(gè)數(shù)據(jù)是否不是NULL
-- 查找sal不為NULL的數(shù)據(jù)
SELECT * FROM emp WHERE sal IS NOT NULL;