Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 506
dpfarhad Avatar asked Jun 05 '13 17:06

dpfarhad


People also ask

What does mean of error?

ˈe-rər. : an act or condition of ignorant or imprudent deviation from a code of behavior. : an act involving an unintentional deviation from truth or accuracy. made an error in adding up the bill.

What is the synonym word for error?

Some common synonyms of error are blunder, lapse, mistake, and slip.

What are errors with example?

An error may be defined as the difference between the measured and actual values. For example, if the two operators use the same device or instrument for measurement. It is not necessary that both operators get similar results. The difference between the measurements is referred to as an ERROR.

What is mistake in error?

Both refer to doing something wrong. However, 'mistake' is less formal and it is insignificant compared to an 'error'. People make mistakes when they already have the knowledge but lack concern and attention. However, 'error' is more formal and when people have errors, it is because the lack the proper knowledge.


2 Answers

where product.owner in (SELECT *

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

like image 162
Explosion Pills Avatar answered Sep 22 '22 07:09

Explosion Pills


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
like image 35
echo_Me Avatar answered Sep 22 '22 07:09

echo_Me