MYSQL:基数违规:1242子查询返回超过1行?

时间:2017-10-13 23:15:54

标签: mysql

我正在使用此查询来搜索标签相似性

SELECT sites_id
    FROM tags_to_sites
    WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
    AND sites_id!= ?
    GROUP BY sites_id
    HAVING COUNT(*) = (  SELECT COUNT(*)  FROM  tags_to_sites
    WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
      AND sites_id!= ?
    GROUP BY sites_id
    ORDER BY COUNT(*) DESC LIMIT 3)

但我收到错误

  

SQLSTATE [21000]:基数违规:1242子查询返回更多   超过1行

有谁知道为什么?

1 个答案:

答案 0 :(得分:0)

正确的查询

SELECT sites_id
    FROM tags_to_sites
    WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
    AND sites_id!= ?
    GROUP BY sites_id
    HAVING COUNT(*) = (  SELECT COUNT(*)  FROM  tags_to_sites
    WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
      AND sites_id!= ?
    GROUP BY sites_id
    ORDER BY COUNT(*) DESC LIMIT 1)
LIMIT 3