Hi,
I have three tables that I would like to join: employee, manager_emp and manager. I would like to see all employees that have managers, along with the manager's name that can be derived from manager table. If an employee does not have a manager then just display NULL. However, I can not figure out how to join third table (manager) and still get the NULLS.
SELECT emp.id, emp.name, emp.dept, mgre.mgrid
FROM employee AS emp
LEFT JOIN manager_emp AS mgre on emp.id = mgre.id
+-----+---------+--------+--------+
| id | name | dept | mgrid |
|-----+---------+--------+--------+
| 3 | fred | IT | m003 |
| 6 | fredola | RISK | m002 |
| 7 | reddy | NULL | NULL |
This is the output I would like:
+-----+---------+--------+--------+---------+
| id | name | dept | mgrid | mgrname |
|-----+---------+--------+--------+---------+
| 3 | fred | IT | m003 | j james |
| 6 | fredola | RISK | m002 | b mike |
| 7 | reddy | NULL | NULL | NULL |
Any assistance would be appreciated.
I have three tables that I would like to join: employee, manager_emp and manager. I would like to see all employees that have managers, along with the manager's name that can be derived from manager table. If an employee does not have a manager then just display NULL. However, I can not figure out how to join third table (manager) and still get the NULLS.
SELECT emp.id, emp.name, emp.dept, mgre.mgrid
FROM employee AS emp
LEFT JOIN manager_emp AS mgre on emp.id = mgre.id
+-----+---------+--------+--------+
| id | name | dept | mgrid |
|-----+---------+--------+--------+
| 3 | fred | IT | m003 |
| 6 | fredola | RISK | m002 |
| 7 | reddy | NULL | NULL |
This is the output I would like:
+-----+---------+--------+--------+---------+
| id | name | dept | mgrid | mgrname |
|-----+---------+--------+--------+---------+
| 3 | fred | IT | m003 | j james |
| 6 | fredola | RISK | m002 | b mike |
| 7 | reddy | NULL | NULL | NULL |
Any assistance would be appreciated.
Comment