首页 文章

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

提问于
浏览
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 3)

但我得到一个错误

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

谁知道为什么?

1 回答

  • 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
    

相关问题