简体   繁体   English

PDOException:SQLSTATE [23000]:违反完整性约束:1052 IN / ALL / ANY子查询中的列“ category_id”不明确

[英]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.

相关问题 Yii2 GridView:SQLSTATE[23000]:违反完整性约束:1052 order 子句中的列“id”不明确 - Yii2 GridView: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous Laravel 6 错误:SQLSTATE[23000]:违反完整性约束:1052 where 子句中的列“id_perusahaan”不明确 - Laravel 6 Error : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_perusahaan' in where clause is ambiguous SQLSTATE[23000]:违反完整性约束:1048 列“category_id”不能为空 - SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category_id' cannot be null SQLSTATE [23000]:完整性约束违规:1052 order order中的'created_at'列不明确Laravel 5.5 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5 SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 Laravel Eloquent SQLSTATE[23000]:违反完整性约束:1052 列...在 where 子句中不明确 - Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 where子句中的列'status'不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 where子句中的列'NRP'不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'NRP' in where clause is ambiguous SQLSTATE[23000]:完整性约束违规:1052 - SQLSTATE[23000]: Integrity constraint violation: 1052
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM