gpt4 book ai didi

php - MySQL "Not IN"查询突然停止返回结果

转载 作者:行者123 更新时间:2023-11-29 04:14:29 26 4
gpt4 key购买 nike

我正在为共享托管环境中的一个站点做一些工作,该环境有翻转我们设置的历史。本周,更新脚本突然停止工作,根本原因是用于返回结果的 NOT IN 子句不再这样做。

本质上,查询是这样的:

SELECT  *
FROM db1.entry
where entry_id not in
(
select entry_id from db2.content
)

我可以通过直接检查这两个表来验证确实有应该返回的记录。运行以下两个查询时,第一个返回 entry_ids 而第二个不返回:

SELECT  *
FROM db1.entry
order by entry_id desc

SELECT *
FROM db2.content
order by entry_id desc

重申一下,几个月来一切正常。没有进行任何代码更改,但可能在此过程中更改了 MySQL 设置。也有可能是 PHP 环境发生了某些变化,但这种可能性似乎较小,因为所讨论的查询在从 phpMyAdmin 运行时以与从实时站点运行时相同的方式失败。

当然,它在我的开发箱上仍然可以完美运行。

实时站点运行的是 MySQL 4.1.11 版。我的问题是,有人知道那个版本的 MySQL 设置会改变这些 NOT IN 查询的工作方式吗?

谢谢。

最佳答案

确保您的内部查询不返回 NULL

来自 documentation :

To comply with the SQL standard, IN returns NULL not only if the expression on the left hand side is NULL, but also if no match is found in the list and one of the expressions in the list is NULL.

关于php - MySQL "Not IN"查询突然停止返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1006945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com