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
How to Find Specific Values in a Table in Oracle
Retrieve String Between HTML Tags Using Regex
Sql Merge Two Rows With Same Id But Different Column Values (Oracle)
How to Convert This SQL Select to Linq Query
Select Distinct Values from One Table and Join With Another Table
Sql. How to Check If Record Exists in Table
A SQL Query to Get All the Records Where 5 Columns Are Same But Only One Column Is Different
Select Only Rows That Contain Only Alphanumeric Characters in MySQL
Select Distinct Records on a Join
Sql Query to Join Two Tables With No Repeated Values
How to Decrypt MySQL Passwords
Mysql - Left Join Takes Too Long, How to Optimize Query
Add Single Quotes to Results in a Column from a SQL Query
Sql Select Count for Multiple Columns in a Single Query
Sql Query to Get the Employee Name and Their Manager Name from the Same Table
Postgresql Query to Return Results as a Comma Separated List