Mysql – Find rows that have the same value on a column in MySQL

duplicationMySQL

In an employee table, some rows have the same value for the reportsTo column.

employeeNumber | reportsTo
---------------|-----------------
1056           | 1002
1076           | 1002
1088           | 1056
1102           | 1056
1143           | 1056
...

I want to be able to show the employee numbers of employees who report to the same person as does a particular employee.

For e.g. I want to know the other employees who report to the same person as employeeNumber 1088

The output should be:

   | employeeNumber |
   |----------------|
   | 1088           |
   | 1102           |
   | 1143           |

What simple MySQL statement I can use to get this result?

Best Answer

One way by using a subquery that returns reportsTo of employeeNumber = 1088

select
from   employees
where  employee.reportsTo = (select reportsTo
                             from   employees
                             where  employeeNumber = 1088);