1

在具有 5000 条记录的 mysql 查询中,在表中:subscriptions [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。任何想法为什么会发生这种情况?

4

1 回答 1

1

NULL不一样0。它根本是未知的,所以如果你也想检查NULL,请使用IS NULL

SELECT * 
FROM subscriptions 
where archive = 0 OR archive IS NULL 
order by id desc 
limit 0, 24
于 2013-03-28T05:00:07.317 回答