i have an error which i dont understand. can you help me? [closed]

Sub queries used for the IN clause can’t return multiple columns, so you can’t have SELECT reportsTo, COUNT( * ) AS count inside it. You probably want to join the subquery instead, something like this:

SELECT firstName,lastName,temp.count
FROM employees
INNER JOIN (
    SELECT reportsTo, COUNT( * ) AS count
    FROM employees
    GROUP BY reportsTo
) temp ON employees.employeeNumber = temp.reportsTo

Disclaimer: I don’t use MySQL so the above syntax may not be exact.

You’ll likely also run into issues trying to use count as a column name. Either rename it or escape it (SQL Server uses [ and ], not sure about MySQL).

Leave a Comment