sql: select 空值问题

sql: select where problem with null value

学生table:

id          name
0           NULL
1           John

查询:

SELECT * from students WHERE name != "John";

预期输出:

0           NULL

我的测试结果是空的,我该如何解决?

SELECT * from students WHERE name != "John" OR name == NULL;

请尝试以下操作,NULL 不是值,因此您无法使用 = 进行比较。看看 DEMO

SELECT * from students WHERE name != 'John' and name is NULL;

这个不错read.

据推测,您想要:

SELECT * from students WHERE name <> 'John' or name is null

假设您是 运行 MySQL,如您的屏幕副本所示,您还可以使用 null-安全运算符

进行表达
SELECT * from students WHERE NOT name <=> 'John'