数据库
首页 > 数据库> > 错误#1241 – 操作数应包含Mysql中的1列

错误#1241 – 操作数应包含Mysql中的1列

作者:互联网

参见英文答案 > Operand Should Contain 1 Column – MySQL NOT IN                                    2个
我只是尝试以下查询:

SELECT *, 
      (
       SELECT count(*) 
       FROM users 
       where users.email=calls.email
      ) as ureg, 
      (
       SELECT sum(qty) 
       FROM product 
       where product.owner in 
          (SELECT * 
           from users 
           where users.email=calls.email)
      ) as pop 
FROM calls 
order by calls.data desc 
LIMIT 0,20

但我得到以下错误:

#1241 - Operand should contain 1 column(s)

我该如何修复我的查询?

编辑:
通过改变
来自users.email = calls.email的用户的SELECT *

来自user.email = calls.email的用户的SELECT id

它的工作原理是因为查询在用户中存在的一堆id中搜索product.owner

解决方法:

where product.owner in (SELECT *

product.owner是一列,因此子查询应返回一列(无论对应于product.owner).

标签:mysql,mysql-error-1241
来源: https://codeday.me/bug/20190712/1443998.html