Професионална програма
Loading...
DMinchev91 avatar DMinchev91 4 Точки

JOINS, Subqueries EX - QUESTION 9

Как да намеря имената на менижърите - аз нещо такова измислих но май съм далеч от истината

SELECT e.employee_id, e.first_name, e.manager_id,
(SELECT first_name FROM employees AS e1 
WHERE e1.employee_id = d.manager_id) AS manager_name 
FROM employees AS e
JOIN departments AS d ON d.manager_id = e.manager_id
WHERE e..manager_id IN (7,3)
ORDER BY e.first_name ASC;

Това ми дава ми дава само тези с id=3 , и като цяло дата е разбъркана.

 

Тагове:
0
Databases Basics - MySQL
Rumyana1984 avatar Rumyana1984 13 Точки
Best Answer

SELECT e.employee_id, e.first_name, e.manager_id, m.first_name AS manager_name

FROM employees AS e

inner JOIN employees AS m

ON e.manager_id = m.employee_id

WHERE m.employee_id IN (3,7)

ORDER BY e.first_name;

0