mysql php查询:为什么包含不相等会影响结果

时间:2022-09-18 13:22:09

In a mysql query with 5000 records, in the table: subscriptions [id autoincrement int, name varchar64, archive tinyint4 ]

在包含5000条记录的mysql查询中,在表中:subscriptions [id autoincrement int,name varchar64,archive tinyint4]

i'm passing the following sql

我正在传递以下sql

$sqlg = "SELECT * FROM subscriptions where archive != 1  order by id desc limit 0,24";

the above returns records between 3061 - 3012

以上返回3061 - 3012之间的记录

If i remove the where clause,

如果我删除where子句,

SELECT * FROM subscriptions order by id desc

it returns, records between 5066 - 5037 which is the correct result i'm looking for with archive having the value of NULL or 0. Any ideas why this might be happening?

它返回,5066 - 5037之间的记录,这是我正在寻找的具有NULL或0值的存档的正确结果。任何想法为什么会发生这种情况?

1 个解决方案

#1


1  

NULL is not the same as 0. It simply is unknown, so if you want to check for NULL also, use IS NULL

NULL与0不同。它只是未知,因此如果您还要检查NULL,请使用IS NULL

SELECT * 
FROM subscriptions 
where archive = 0 OR archive IS NULL 
order by id desc 
limit 0, 24

#1


1  

NULL is not the same as 0. It simply is unknown, so if you want to check for NULL also, use IS NULL

NULL与0不同。它只是未知,因此如果您还要检查NULL,请使用IS NULL

SELECT * 
FROM subscriptions 
where archive = 0 OR archive IS NULL 
order by id desc 
limit 0, 24