57. Chain of Doctors

Hard Self Join
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
patients
10 cols
doctors
4 cols
admissions
7 cols
province_names
2 cols

Reference Solution

Expected SQL
SELECT d1.last_name, d2.last_name, d3.last_name FROM doctors d1 JOIN doctors d2 ON d1.specialty = d2.specialty JOIN doctors d3 ON d2.first_name = d3.first_name WHERE d1.doctor_id != d2.doctor_id AND d2.doctor_id != d3.doctor_id;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.