一切似乎都运转良好,突然之间我在前端得到了这个错误:
致命错误:带有消息的未捕获异常'PDOException' 'SQLSTATE [21000]:基数违规:1242子查询返回更多 在/var/www/html/system/home.php:78堆栈跟踪:#0 /var/www/html/system/home.php(78):PDOStatement-> execute()#1 {main} 在第78行的/var/www/html/system/home.php中引用
在Workbench下,我之前创建的每个VIEW都会发出此错误: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。
提前谢谢
答案 0 :(得分:2)
当您的子查询返回时,将返回错误代码1242 不止一行进行比较。
请检查您是否错误地插入了任何重复数据。