mysqlsqloperand

mysql SELECT query syntax issue


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 ?


Solution

  • 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.