Home > Blockchain >  Why does operand should contain 1 column(s) error appear when I don't use a subquery?
Why does operand should contain 1 column(s) error appear when I don't use a subquery?

Time:12-26

I am trying to run this MYSQL query:

SELECT COMPANY.COMPANY_CODE, COUNT(LEAD_MANAGER.LEAD_MANAGER_CODE), COMPANY.FOUNDER
FROM COMPANY INNER JOIN LEAD_MANAGER
WHERE COMPANY.COMPANY_CODE = LEAD_MANAGER.COMPANY_CODE
GROUP BY(COMPANY.COMPANY_CODE, COMPANY.FOUNDER);

The error I receive is:

ERROR 1241 (21000) at line 1: Operand should contain 1 column(s)

I don't understand why I am getting this error because from the research I've done this error appears due to a subquery returning more than one column when SQL expects only one column. However, my code does not use a subquery.

CodePudding user response:

Join properly with ON and remove the parentheses around GROUP BY

SELECT COMPANY.COMPANY_CODE, 
       COUNT(LEAD_MANAGER.LEAD_MANAGER_CODE), 
       COMPANY.FOUNDER
FROM COMPANY 
INNER JOIN LEAD_MANAGER ON COMPANY.COMPANY_CODE = LEAD_MANAGER.COMPANY_CODE
GROUP BY COMPANY.COMPANY_CODE, 
         COMPANY.FOUNDER

CodePudding user response:

GROUP BY is not a function, lose the parentheses:

SELECT COMPANY.COMPANY_CODE, COUNT(LEAD_MANAGER.LEAD_MANAGER_CODE), COMPANY.FOUNDER
FROM COMPANY INNER JOIN LEAD_MANAGER
WHERE COMPANY.COMPANY_CODE = LEAD_MANAGER.COMPANY_CODE
GROUP BY COMPANY.COMPANY_CODE, COMPANY.FOUNDER;
  • Related