gpt4 book ai didi

mysql - SQLSTATE[42S02] - 来自子查询

转载 作者:行者123 更新时间:2023-11-29 15:38:22 36 4
gpt4 key购买 nike

MYSQL 在处理通过别名调用的表的子查询时触发 SQLSTATE[42S02] 错误

“更新 call_log AS c1 INNER JOIN call_log AS c2 ON c1.id = c2.id SET c1.end ='".$reponse."' WHERE c1.id = (SELECT MAX(c2.id) FROM (SELECT * from c2 WHERE c2.num =".$numero.") 派生)";

期望的结果是更新 call_log 表中包含 $num 变量的最后一个匹配行。由于 MYSQL 阻止基于同一个表进行子查询,因此我按照此处的建议使用别名来引用这些表

mySQL error: #1248 - Every derived table must have its own alias

或这里 What is the error "Every derived table must have its own alias" in MySQL?

我得到的错误是:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ERP.c2' doesn't exist'

最佳答案

好的,我发现了这个问题。我稍微更改了命令以简化请求。

$sql ="UPDATE call_log as c1 SET c1.end = '".$reponse."' WHERE c1.id = (SELECT MAX(derive.id) FROM (SELECT * FROM call_log c2) derive WHERE derive.num =".$numero.")";

主要区别在于我为表本身创建了一个别名 c2 但是我还使用 (SELECT * FROM call_log c2)derive 的别名,其中 < em>derive 将是过滤子查询结果的别名!!

如果对别人有帮助......

关于mysql - SQLSTATE[42S02] - 来自子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57977429/

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