开发者

mySQL error need some help

开发者 https://www.devze.com 2022-12-19 20:21 出处:网络
I am trying to run a nested query but I am getting this error, #1241 - Operand should contain 1 column(s)

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 开发者_运维技巧


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消