在一个有 5000 条记录的 mysql 查询中, 在表中:订阅 [id autoincrement int, name varchar64, archive tinyint4 ]
我正在传递以下 sql
$sqlg = "SELECT * FROM subscriptions where archive != 1 order by id desc limit 0,24";
以上返回 3061 - 3012 之间的记录
如果我删除 where 子句,
SELECT * FROM subscriptions order by id desc
它返回 5066 - 5037 之间的记录,这是我正在寻找的正确结果,存档的值为 NULL 或 0。 任何想法为什么会发生这种情况?
最佳答案
NULL
与 0
不同。它只是未知的,所以如果您还想检查 NULL
,请使用 IS NULL
SELECT *
FROM subscriptions
where archive = 0 OR archive IS NULL
order by id desc
limit 0, 24
关于mysql php 查询 : why does a including not equal affect the results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15674571/