HomeInterview QuestionsWrite a three‑table JOIN query to link the patient…

Write a three‑table JOIN query to link the patients, admissions, and doctors tables, filtering by diagnosis 'Epilepsy' and doctor's first name 'Lisa'.

🟡 Medium Coding Mid level
1Times asked
Aug 2026Last seen
Aug 2026First seen

💡 Model Answer

SELECT p.patient_id, p.first_name, p.last_name, a.admission_date, d.first_name AS doctor_first, d.last_name AS doctor_last

FROM patients p

JOIN admissions a ON p.patient_id = a.patient_id

JOIN doctors d ON a.doctor_id = d.doctor_id

WHERE a.diagnosis = 'Epilepsy'

AND d.first_name = 'Lisa';

Explanation: The query starts with the patients table, joins admissions on patient_id, then joins doctors on doctor_id. The WHERE clause filters admissions with the diagnosis 'Epilepsy' and doctors whose first name is 'Lisa'. The result set includes patient details, admission date, and the doctor's name. Complexity is O(n) relative to the number of rows in the joined tables, assuming appropriate indexes on patient_id, doctor_id, and diagnosis. Indexes on these columns will make the join and filter operations efficient.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500