簡體   English   中英

MySQL錯誤需要一些幫助

[英]mySQL error need some help

我正在嘗試運行嵌套查詢,但出現此錯誤,

#1241 - Operand should contain 1 column(s)

這是我要運行的查詢,

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 

第5行應該是

SELECT `categoryTable`.`categoryId`

即它應該只引用categoryId。
換句話說,使用WHERE xyz [NOT] IN (SELECT ...謂詞)時,嵌套的select中應該只有一列,對應於“ xyz”列,但當然不必命名相同。原因是SQL不會知道要使用嵌套查詢的哪一列與“ xyz”列進行比較;另一個原因是其他列無用,為什么要引入它們呢?

是。 我同意@mjv,基本上您正在檢查categoryId ID是否不在列表中

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

因此,您只需要提及一個字段categoryID ,它將檢查該字段是否不在此列表中。

希望這有道理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM