Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subqueries answer is wrong #19

Open
Eihrana opened this issue Feb 7, 2022 · 0 comments
Open

Subqueries answer is wrong #19

Eihrana opened this issue Feb 7, 2022 · 0 comments

Comments

@Eihrana
Copy link

Eihrana commented Feb 7, 2022

Question:

/*

  • DB: Employees
  • Table: employees
  • Question: Filter employees who have emp_no 110183 as a manager
    */

Answer:

-- Written with JOIN
SELECT e.emp_no, first_name, last_name
FROM employees as e
JOIN dept_emp as de USING (emp_no)
JOIN dept_manager as dm USING (dept_no)
WHERE dm.emp_no = 110183

In this answer, if we write it like that we will see all the employees who are in the department - d003.
In that dep are 2 managers. and emp_no = 110183 was manager only until 1992-03-21.

My resolution to this:

Select * from "public"."employees" as e
join dept_emp as de on de.emp_no = e.emp_no
join dept_manager as d on d.dept_no = de.dept_no

where d.emp_no = 110183 and de.to_date <= '1992-03-21'
.

Let me know if I'm wrong. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant