sql:select where有空值的问题

问题描述 投票:0回答:1

学生表。

id          name
0           NULL
1           John

查询:

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

预期的输出:

0           NULL

用我的测试,结果是空的,我怎么解决这个问题?

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

Screen

sql where-clause
1个回答
2
投票

大概,你想。

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

假设你运行的是MySQL,就像你的屏幕拷贝所建议的那样,你也可以用以下方法来表达 null-安全运营商

SELECT * from students WHERE NOT name <=> 'John'

0
投票

试试下面的方法。NULL 不是值,所以你不能用 =看一看 演示

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

这是个好东西 阅读.

© www.soinside.com 2019 - 2024. All rights reserved.