user5400577
user5400577

Reputation:

SQL ERROR Operand should contain 1 column(s)

Where am I going wrong?

If I do this

SELECT CONCAT('$',TRUNCATE(AVG(`payper`),2)) AS `Average Pay` 
FROM `rep_commission` 
WHERE type IN (SELECT type ='TV','NET','FONE')

I get

Operand should contain 1 column(s)

If I try this,

SELECT CONCAT('$',TRUNCATE(AVG(payper),2)) AS Average Pay
FROM rep_commission WHERE type=('TV', 'NET', 'FONE')

I get

Operand should contain 1 column(s)

If I try this,

SELECT CONCAT('$',TRUNCATE(AVG(`payper`),2)) AS `Average Pay` FROM `rep_commission` WHERE type='TV', 'NET', 'FONE'

I get

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'NET', 'FONE'' at line 1

If I do,

SELECT CONCAT('$',TRUNCATE(AVG(`payper`),2)) AS `Average Pay` FROM `rep_commission` WHERE type='TV'

I get

Average Pay

$99.99

Which is what I am after, but the ONE type...

Google, Chat, and other SO questions lead me to the previous attempts that get Operand ?

Upvotes: 0

Views: 225

Answers (1)

Rahul
Rahul

Reputation: 77876

Yes, because you are doing it wrong. You should be using a IN operator like below since = operator can work with only a single value and not multiple values

SELECT CONCAT('$',TRUNCATE(AVG(payper),2)) AS `Average Pay`
FROM rep_commission WHERE type IN ('TV', 'NET', 'FONE')

In your first query as well where you say below is totally wrong

WHERE type IN (SELECT type ='TV','NET','FONE')

It should rather be

WHERE type IN (
SELECT 'TV'
UNION 
SELECT 'NET'
UNION
SELECT 'FONE')

(OR) Simply

WHERE type IN ('TV', 'NET', 'FONE')

Upvotes: 3

Related Questions