operand should contain 1 columns [duplicate]

2019-02-27 09:58发布

This question already has an answer here:

SELECT topic_id
FROM phpbb_topics AS t
WHERE t.topic_id IN (
    SELECT p.topic_id, COUNT(p.post_id) AS total_posts
    FROM phpbb_posts AS p
    WHERE p.poster_id = 61640
    GROUP BY p.topic_id
    HAVING t.topic_replies_real = total_posts - 1
);

That query gets me the following error:

Error Code: 1241. Operand should contain 1 column(s)

Any ideas?

1条回答
神经病院院长
2楼-- · 2019-02-27 10:11

You shouldn't include COUNT(p.post_id) AS total_posts in SELECT list in your subquery. Just

SELECT topic_id   
FROM phpbb_topics AS t
WHERE t.topic_id IN (
    SELECT p.topic_id --, COUNT(p.post_id) AS total_posts 
    FROM phpbb_posts AS p
    WHERE p.poster_id = 61640
    GROUP BY p.topic_id
    HAVING t.topic_replies_real = COUNT(p.post_id) - 1
);
查看更多
登录 后发表回答