Chapter 5 · JOINs
63. Doctor Pairs in the Same Department
Medium20 XPHealthcare
Administration wants to list all pairs of doctors who work in the same department. Return doctor1_name, doctor2_name, and department_id. Ensure each pair appears only once (doctor1 id < doctor2 id). Order by department_id, doctor1_name.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- specialtyTEXT
- FKdepartment_id→ departments.idINT
- emailTEXT
- phoneTEXT
- hire_dateTEXT
- salaryREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.