[英]PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'category_id' in IN/ALL/ANY subquery is ambiguous
got a select within a select statement and I'm not sure why the result is ambiguous! 在select语句中有一个select,但我不确定结果为何不明确!
my (php) function: 我的(php)函数:
function FunctionName($EventId) {
$database = new Connection();
$database = $database->Connect();
$statement = $database->prepare(" SELECT C.*
FROM event_categories AS C
LEFT JOIN event_in_categories as EC
ON C.category_id = EC.category_id
LEFT JOIN events AS E
ON EC.EventId = E.EventId
WHERE category_id IN
(
SELECT EC.category_id FROM event_in_categories
WHERE EventId = :EventId
)
AND category_active = 1 ");
$statement->execute(array("EventId" => $EventId));
$Categories = $statement->fetchall(PDO::FETCH_ASSOC);
if (!empty($Categories)) {
foreach ($Categories as $Category) {
$CategoryArray[] = new EventCategory(null, $Category);
}
return $CategoryArray;
}
}
I specified which ID in the second select and I still get the error. 我在第二个选择中指定了哪个ID,但仍然收到错误。 (I researched, came across PHP MySQL - Column 'id' in IN/ALL/ANY subquery is ambiguous amended my second select so it specifies which ID to read and same error) (我研究过,碰到PHP MySQL-IN / ALL / ANY子查询中的列'id'是模糊的,修改了第二个选择,因此它指定要读取的ID和相同的错误)
Any help given would be much appreciated :D 给出的任何帮助将不胜感激:D
You have to add the alias from wich column you id should be: 您必须从ID应当为该列添加别名:
Please change: 请更换:
WHERE category_id IN
TO 至
WHERE C.category_id IN
在子查询中
SELECT category_id FROM event_in_categories
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.