-2

I have a table Employees with emp_no and employees' info but there isn't a column specifying their manager at all.

The names of the managers and their emp_no are in the Employees table with the rest of the staff. The managers' emp_no and dept_no are present in the dept_manager table. The active managers have value 9999-01-01 in column to_date in dept_manager. In a 3rd table dept_emp, I have the emp_no and dept_no of each employee.

I tried to use left join to add the manager names against the employees'names but I get an error:

SELECT (concat(first_name, ' ',last_name)) as EmployeeName, 
(concat(first_name, ' ', last_name)) as Managersname,
FROM employees AS emp 
LEFT JOIN dept_manager AS dm ON emp.emp_no=dm.emp_no
LEFT JOIN dept_emp as de on dm.dept_no=de.dept_no and dm.to_date='9999-01-01';

Any better ideas about how to get the results right?

Thanks, GV

Г В
  • 1
  • 1
  • It is missing information on how to know which Manager corresponds to an Employee. Before trying to solve it with SQL, try to find a way to get that info "in english" – MundoPeter Sep 13 '20 at 13:25
  • Please in code questions give a [mre]--cut & paste & runnable code, including smallest representative example input as code; desired & actual output (including verbatim error messages); tags & versions; clear specification & explanation. Give the least code you can give that is code that you show is OK extended by code that you show is not OK. (Debugging fundamental.) For SQL that includes DBMS & DDL (including constraints & indexes) & input as code formatted as a table. [ask] Stop trying to code your overall goal & explain what you expected instead from the given code & why. – philipxy Sep 13 '20 at 22:24

1 Answers1

0
SELECT (concat(emp.first_name, ' ', emp.last_name)) as EmployeeName, 
(concat(dm.first_name, ' ', dm.last_name)) as Managersname 
FROM employees AS emp LEFT JOIN dept_manager AS dm ON emp.emp_no=dm.emp_no  
WHERE dm.to_date='9999-01-01';
Chayne P. S.
  • 1,558
  • 12
  • 17