Mysql - Operand Should Contain 1 Column(S)

MySQL - Operand should contain 1 column(s)

Your subquery is selecting two columns, while you are using it to project one column (as part of the outer SELECT clause). You can only select one column from such a query in this context.

Consider joining to the users table instead; this will give you more flexibility when selecting what columns you want from users.

SELECT
topics.id,
topics.name,
topics.post_count,
topics.view_count,
COUNT( posts.solved_post ) AS solved_post,
users.username AS posted_by,
users.id AS posted_by_id

FROM topics

LEFT OUTER JOIN posts ON posts.topic_id = topics.id
LEFT OUTER JOIN users ON users.id = posts.posted_by

WHERE topics.cat_id = :cat
GROUP BY topics.id

MySQL: Error: Operand should contain 1 column(s). What's wrong with my use of WHERE...NOT IN(SELECT...)?

You are close. But NOT IN does work that way -- because the subquery returns multiple columns. And you are comparing to only one value. Instead, use two separate comparisons:

SELECT activity
FROM a
WHERE n <> (SELECT MAX(n) FROM a) AND
n <> (SELECT MIN(n) FROM a) ;

#1241 - Operand should contain 1 column(s) nested query

First of all you should match your columns in the IN function:

WHERE User.UserId=Borrowed_Book.UserId  IN (
SELECT *
FROM Book , Book_version_info
WHERE
Book_version_info.PublisherID = 1 AND
Book.ISBN= Book_version_info.Book_ISBN
);

SQL does not know what to do with that the columns should be same so try instead:

WHERE User.UserId=Borrowed_Book.UserId  AND User.UserId IN (
SELECT User.UserId
FROM Book , Book_version_info, User
WHERE
Book_version_info.PublisherID = 1 AND
Book.ISBN= Book_version_info.Book_ISBN
);

how can i solve following issue: #1241 - Operand should contain 1 column(s)

The query:

select product_id, product_name, product_price, product_image 
from tbl_product
where product_id=1

returns the columns that you want, but for INSERT ... VALUES it is syntactically wrong, to use a query that returns more than 1 column.

Use INSERT ... SELECT:

insert into tbl_cart (ssid, product_id,product_name,product_price,product_image,quantity) 
select 1234, product_id, product_name, product_price, product_image, 1
from tbl_product
where product_id=1;


Related Topics



Leave a reply



Submit