Mysql 错误代码:1242 子查询 returns 多于 1 行

Mysql Error code: 1242 Subquery returns more than 1 row

一切似乎都很好,然后突然间我的前端出现了这个错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row' in /var/www/html/system/home.php:78 Stack trace: #0 /var/www/html/system/home.php(78): PDOStatement->execute() #1 {main} thrown in /var/www/html/system/home.php on line 78

在 Workbench 下,我之前创建的每个视图都发出此错误:Mysql Error code: 1242 Subquery returns more than 1 row.

这是一个给出错误的代码示例。

SELECT 
    `teams`.`id` AS `id`,
    `teams`.`name` AS `team_name`,
    `teams_and_captains_view`.`captain` AS `captain`,
    IF((`teams`.`gender` = 'M'),
        'Male',
        'Female') AS `gender`,
    (SELECT 
            `categories`.`name`
        FROM
            `categories`
        WHERE
            (`categories`.`id` = `teams`.`category_id`)) AS `category`,
    `teams`.`category_id` AS `category_id`,
    `teams`.`slogan` AS `slogan`,
    `teams`.`location` AS `location`,
    `teams`.`description` AS `description`,
    `teams`.`phone` AS `phone`,
    `teams`.`email` AS `email`,
    `teams`.`tournament_id` AS `tournament_id`,
    (SELECT 
            COUNT(`players`.`id`)
        FROM
            `players`
        WHERE
            (`players`.`team_id` = `teams`.`id`)) AS `players`,
    `teams_and_captains_view`.`captain_id` AS `captain_id`
FROM
    (`teams`
    LEFT JOIN `teams_and_captains_view` ON ((`teams`.`id` = `teams_and_captains_view`.`id`)))

我用LIMIT好像可以,但是我不能用LIMIT。

提前致谢

当您的子查询returns时将返回错误代码 1242 不止一行用于比较。

请检查您是否误插入了重复数据。

http://dev.mysql.com/doc/refman/5.7/en/subquery-errors.html