SQL ERROR: The operand must contain 1 column (s)

I have this query and I get the error "The operand must contain 1 column", what is wrong in my query?

SELECT * FROM contact AS b WHERE b.id IN ( SELECT * FROM contact AS e WHERE e.firstname LIKE ? OR e.lastname LIKE ? OR e.email LIKE ? OR e.phone LIKE ? OR e.company LIKE ? OR e.profession LIKE ? OR e.mobile LIKE ? ) 
+4
source share
5 answers

The IN statement expects a list of values ​​that match what you are comparing: columnb.id in your case. Therefore replace it

 WHERE b.id IN (SELECT * 

with this

 WHERE b.id IN (SELECT id 
+10
source

The second choice should be SELECT id insetad SELECT * .

+7
source

WHERE uses IN to determine which b.id values ​​are relevant to your query. To use IN your second query, you need to return only one column.

+3
source
 SELECT * FROM 

The problem in the above statement is because you select more than one column,

change it to

 SELECT * FROM contact AS b WHERE b.id IN (SELECT e.ID FROM contact AS e WHERE e.firstname LIKE ? OR e.lastname LIKE ? OR e.email LIKE ? OR e.phone LIKE ? OR e.company LIKE ? OR e.profession LIKE ? OR e.mobile LIKE ?) 
+2
source
  SELECT * FROM contact AS b WHERE b.id IN (SELECT e.Id FROM contact AS e WHERE e.firstname LIKE ? OR e.lastname LIKE ? OR e.email LIKE ? OR e.phone LIKE ? OR e.company LIKE ? OR e.profession LIKE ? OR e.mobile LIKE ?) 

Instead of SELECT * FROM contact it should be a column that contains values ​​corresponding to b.id

So this should be SELECT e.Id FROM contact

+1
source

All Articles