SQL exercises on hospital Database: Find the name and medication for those patients who did not take any appointment
SQL hospital Database: Exercise-21 with Solution
21. Write a query in SQL to find the name and medication for those patients who did not take any appointment.
Sample table: patient
Sample table: prescribes
Sample table: physician
Sample table: medication
SELECT t.name AS "Patient", p.name AS "Physician", m.name AS "Medication" FROM patient t JOIN prescribes s ON s.patient=t.ssn JOIN physician p ON s.physician=p.employeeid JOIN medication m ON s.medication=m.code WHERE s.appointment IS NULL;
Patient | Physician | Medication ------------+-------------+------------ Dennis Doe | Molly Clock | Thesisin (1 row)
E R Diagram of Hospital Database:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query in SQL to find the name of the patients who taken an advanced appointment, and also display their physicians and medication.
Next: Write a query in SQL to count the number of available rooms in each block.
What is the difficulty level of this exercise?