Resolved: using the exists key word
Hi, I am trying to understand why this code does not give me the right result for the first part of the question. Generaly speaking, it is a logical code isn't it?
You should add a WHERE clause in the subquery. Using EXISTS that way follow the syntax:
SELECT column_names FROM table_1 t1 WHERE EXISTS (SELECT column_name FROM table_2 t2 WHERE t1.matching_column = t2.matching_column)
Hence, the CASE statement would be:
CASE WHEN EXISTS (SELECT dm.emp_no FROM dept_manager dm WHERE e.emp_no = dm.emp_no) THEN 'Manager' ELSE 'Employee' END AS is_manager
I personally tried the IN for that problem and got the same result also.
SELECT e.emp_no, e.first_name, e.last_name, CASE WHEN e.emp_no IN ( SELECT emp_no FROM dept_manager) THEN 'Manager' ELSE 'Employee' END AS is_manager FROM employees e WHERE e.emp_no > 109990;
If this helps, an upvote would be appreciated.
Interesting, what error/s have you encountered?
I got the same result as the part 1 problem with both codes.
Hi Kfir and Carl!
Thanks for reaching out.
Thanks for sharing this piece of information with the Community!
Could you please share with us a screenshot of the whole error message you've encountered? This can help us assist you better. Thank you.
Looking forward to your answer.