SELECT * FROM `question` WHERE que_id =(select * from emp_qusans where emp_id=9 and ans!=3)
The query throws the following error message.
1241 - Operand should contain 1 column(s)
How can i fix it ?
SELECT * FROM `question` WHERE que_id =(select * from emp_qusans where emp_id=9 and ans!=3)
The query throws the following error message.
1241 - Operand should contain 1 column(s)
How can i fix it ?
Please make sure your sub query returns one row and you need to use column name instead of * in your sub query.
SELECT *
FROM question
WHERE que_id = (select [column name]
from emp_qusans
where emp_id=9 and ans!=3)
Instead of * you should provide column name.
SELECT * FROM question WHERE que_id =(select [column_name] from emp_qusans where emp_id=9 and ans!=3)
There are two issues in your query
use in clause instead of = your sub query returns full table emp_qusans, please specify a column from this table.
Your query would be like this
SELECT * FROM question
WHERE que_id in (select eq.column1 from emp_qusans eq where eq.emp_id=9 and eq.ans!=3)
SELECT * FROM question WHERE que_id =(select [column_name] from emp_qusans where emp_id=9 and ans!=3)
From the table structure you shared with us, you probably intend to select the qid
column in your subquery:
SELECT *
FROM question
WHERE que_id = (SELECT qid FROM emp_qusans WHERE emp_id = 9 AND ans != 3)
By the way, the operand error you were getting was happening because SELECT *
returns multiple columns (read: values), but you were trying to compare this to a single scalar column. Obviously, that doesn't make any sense.