0
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 ?

1w3j
  • 566
  • 8
  • 24
Chetan
  • 133
  • 1
  • 5
  • 17

5 Answers5

1

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)
Paul Karam
  • 4,052
  • 8
  • 30
  • 53
Anwar Khan
  • 349
  • 1
  • 5
0

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)

0

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)

0

SELECT * FROM question WHERE que_id =(select [column_name] from emp_qusans where emp_id=9 and ans!=3)

0

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360