今天在操作opencart后台时,发现打开分类页面有错误信息
MySql语句错误[Err] 1242 - Subquery returns more than 1 row,这是说SQL语句中的子查询返回的结果不止一行。
下面是我的SQL语句:
[sql]
SELECT DISTINCT *,
(SELECT GROUP_CONCAT(cd1.name ORDER BY level SEPARATOR ' > ')
FROM npa_category_path cp
LEFT JOIN npa_category_description cd1
ON (cp.path_id = cd1.category_id AND cp.category_id != cp.path_id)
WHERE
cp.category_id = c.category_id
AND
cd1.language_id = '1'
GROUP BY cp.category_id) AS path,
(SELECT keyword FROM npa_url_alias WHERE query = 'category_id=241') AS keyword FROM npa_category c LEFT JOIN npa_category_description cd2 ON (c.category_id = cd2.category_id) WHERE c.category_id = '241' AND cd2.language_id = '1'
[/sql]
解决办法:将整个SQL语句里的子查询放到数据库里运行测试一下,如果碰到返回两行数据的子查询语句,那就把数据里有重复的数据删掉一行吧。要不然就修改SQL语句,在出错的子查询语句里限制返回的结果行数 LIMIT 1。
--转自