sql - MySQL - Operand should contain 1 column(s) -
while working on system i'm creating, attempted use following query in project:
select topics.id, topics.name, topics.post_count, topics.view_count, count( posts.solved_post ) solved_post, (select users.username posted_by, users.id posted_by_id users users.id = posts.posted_by) topics left outer join posts on posts.topic_id = topics.id topics.cat_id = :cat group topics.id
":cat" bound php code i'm using pdo. 2 valid value ":cat".
that query though gives me error: "#1241 - operand should contain 1 column(s)"
what stumps me think query work no problem. selecting columns, selecting 2 more table, , continuing on there. can't figure out problem is.
is there simple fix this, or way write query?
your subquery selecting 2 columns, while using project 1 column (as part of outer select
clause). can select 1 column such query in context.
consider joining users
table instead; give more flexibility when selecting columns want users
.
select topics.id, topics.name, topics.post_count, topics.view_count, count( posts.solved_post ) solved_post, users.username posted_by, users.id posted_by_id topics left outer join posts on posts.topic_id = topics.id left outer join users on users.id = posts.posted_by topics.cat_id = :cat group topics.id
Comments
Post a Comment