Self Join: Find Pairs of Employees in the Same Department
Hard
joins
Meta
LinkedIn
Google
Use a self join on the employees table to list all unique pairs of employees who share the same department. Avoid duplicate pairs (A,B) and (B,A) by requiring the first employee's id to be less than the second's.
Expected Output
| emp1 | emp2 | dept_name |
|---|---|---|
| Alice | Bob | Engineering |
| Alice | Carol | Engineering |
| Bob | Carol | Engineering |
| Dave | Eve | Marketing |
Tables
Hints (3 available)
SQL Editor
Output
Click "Run" to see results...