Bird
0
0

How can you modify a self join query to find employees who do not have a manager (top-level employees)?

hard📝 Application Q9 of 15
PostgreSQL - Joins in PostgreSQL
How can you modify a self join query to find employees who do not have a manager (top-level employees)?
AUse LEFT JOIN and filter WHERE manager_id IS NULL
BUse INNER JOIN and filter WHERE manager_id IS NOT NULL
CUse RIGHT JOIN and filter WHERE manager_id IS NULL
DUse FULL JOIN and filter WHERE manager_id IS NOT NULL
Step-by-Step Solution
Solution:
  1. Step 1: Use LEFT JOIN to keep all employees

    LEFT JOIN keeps all rows from the left table even if no match in right table.
  2. Step 2: Filter employees with no manager

    Employees with NULL manager_id have no manager, so filter WHERE manager_id IS NULL.
  3. Final Answer:

    Use LEFT JOIN and filter WHERE manager_id IS NULL -> Option A
  4. Quick Check:

    Find top-level employees = LEFT JOIN + NULL filter [OK]
Quick Trick: LEFT JOIN + WHERE manager_id IS NULL finds top employees [OK]
Common Mistakes:
  • Using INNER JOIN excludes top employees
  • Using RIGHT or FULL JOIN unnecessarily
  • Filtering wrong NULL conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes