mysql php 查询 : why does a including not equal affect the results

标签 mysql sql select

在一个有 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。 任何想法为什么会发生这种情况?

最佳答案

NULL0 不同。它只是未知的,所以如果您还想检查 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/

相关文章:

mysql - 如何使用if函数从一个表获取数据到另一个表

php - 将 PHP 分页添加到搜索结果

php - 如何每 30 天自动更新数据库中的账户余额

java - 如果设置了标志,则 JDBC (My)SQL 仅获取单元格数据

c# - 获取自增 PK 列的值

sql - "select from table1, table2 "意味着什么操作?

mysql - 按最高和最低排序

sql - R:(SQL 风格)%LIKE% 语句

c++ - MySQL Connect/C++ 64 位构建错误

mysql - 如何从mysql中的连接表中查找单行数据?