tags:

views:

11

answers:

2

I am trying to run a nested query but I am getting this error,

#1241 - Operand should contain 1 column(s)

this is the query that I am trying to run,

SELECT *
FROM `categoryTable`
WHERE `categoryId` NOT
IN (
SELECT `categoryTable`.`categoryId` , `categoryTable`.`categoryTitle` , `userMenuTable`.`menuEntryId`
FROM (
`categoryTable`
)
LEFT JOIN `userMenuTable` ON `categoryTable`.`categoryId` = `userMenuTable`.`categoryId`
WHERE `userMenuTable`.`cookieId` = 'bang4b696152b4869'
)
LIMIT 0 , 30 
A: 

5th line should be

SELECT `categoryTable`.`categoryId`

i.e. it should only reference categoryId.
In other words, with the WHERE xyz [NOT] IN (SELECT ... predicate, there should only be one column in the nested select, one corresponding to the "xyz" column but of course not necessarily named the same. The reason is that SQL wouldn't know which column of the nested query to use for comparing with the "xyz" column; a lesser reason is that the other columns are useless, why bring them in?

mjv
if you count from 0 :) do you meen 5th line?
Charles Beattie
LOL, Charles, right, I meant the 5th -edited accordingly- I've been zero-based for too long ;-)
mjv
A: 

Yes. I agree with @mjv, basically you are checking to see if categoryId is not in the list of

`SELECT `categoryTable`.`categoryId` , `categoryTable`.`categoryTitle` , `userMenuTable`.`menuEntryId`
FROM (
`categoryTable`
`

So you need to mention only one field categoryID and it will check to see if it is not in this list.

Hope this makes some sense.

JPro