For instance I have a table called employees where it consists of "Employee ID", "First Name", "Last Name", "Manager ID". To count the subordinate of each manager, I tried to self-joining between the 2 tables.
SELECT e1.first_name, e1.last_name, COUNT(e1.employee_id)
FROM employee e1 INNER JOIN e2 ON e1.employee_id = e2.manager_id
GROUP BY e1.first_name, e1.last_name
Am I right? Also, if I want to join with other tables after self-joining, is the joining statement right?
FROM ((self-joining) INNER JOIN other tables ON "common column")
Combining the first and last name:
SELECT CONCAT(e1.first_name,' ',e1.last_name) "Full Name", COUNT(e1.employee_id)
FROM employee e1 INNER JOIN e2 ON e1.employee_id = e2.manager_id
GROUP BY "Full Name"
I can't compile this....What is wrong?