tags:

views:

141

answers:

5

I have this query and I get error "Operand should contain 1 column(s)", whats 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 ?
)
+2  A: 
SELECT * FROM

the problem in the above statement, because you are selecting 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 ?)
Wael Dalloul
+2  A: 

Your WHERE clause uses IN to determine which values of b.id are relevant for your query. In order to use IN your second query in there must return only one column.

KB22
+4  A: 

The IN operator expects a list of values which match whatever you are comparing against: the columnb.id in your case. So replace this

WHERE b.id IN (SELECT *

with this

WHERE b.id IN (SELECT id
davek
+3  A: 

The second select should be SELECT id insetad of SELECT *.

Konamiman
+1  A: 
    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 which contains values matching to b.id.

So, it should be SELECT e.Id FROM contact

shahkalpesh