SQL 错误:操作数应包含 1 列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1713829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:22:57  来源:igfitidea点击:

SQL ERROR: Operand should contain 1 column(s)

sql

提问by newbie

I have this query and I get error "Operand should contain 1 column(s)", whats wrong in my query?

我有这个查询,我收到错误“操作数应该包含 1 列”,我的查询有什么问题?

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 ?
)

回答by davek

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

IN 运算符需要一个与您正在比较的内容相匹配的值列表:您的情况下的 columnb.id。所以更换这个

WHERE b.id IN (SELECT * 

with this

有了这个

WHERE b.id IN (SELECT id 

回答by Konamiman

The second select should be SELECT idinsetad of SELECT *.

第二个选择应该SELECT id插入SELECT *.

回答by KB22

Your WHEREclause uses INto 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.

您的WHERE子句使用IN来确定 b.id 的哪些值与您的查询相关。为了在您的第二个查询中使用 IN,必须只返回一列。

回答by Wael Dalloul

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 ?)

回答by shahkalpesh

    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.

而不是SELECT * FROM contact,它应该是包含与 匹配的值的列b.id

So, it should be SELECT e.Id FROM contact

所以,应该是 SELECT e.Id FROM contact