Error #1241 - Operand should contain 1 column(s) in Mysql [duplicate]

人走茶凉 提交于 2019-12-23 20:13:20

问题


I just try following query:

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

but I get following error :

#1241 - Operand should contain 1 column(s)

How should I fix my query?

Edit: by changing SELECT * from users where users.email=calls.email to SELECT id from users where users.email=calls.email

it works because the query searches for product.owner in bunch of ids that exist in users


回答1:


where product.owner in (SELECT *

product.owner is one column, so the subquery should return one column (whatever corresponds to product.owner).




回答2:


try this

 SELECT calls.*, count(users.*) as ureg, sum(twons.qty) as pop 
 FROM calls 
 INNER JOIN users ON users.email=calls.email
 INNER JOIN towns ON towns.id = users.town 
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^--you have to correct this to your table column names
  order by data desc 
  LIMIT 0,20
  • you have to correct this ON towns.id = users.town to your tables names


来源:https://stackoverflow.com/questions/16945867/error-1241-operand-should-contain-1-columns-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!