w3resource
SQL exercises

SQL exercises on hospital Database: Find the name of the physicians who are not a specialized physician

SQL hospital Database: Exercise-11 with Solution

11. Write a query in SQL to obtain the name of the physicians who are not a specialized physician.

Sample table: physician


Sample Solution:

SELECT p.name AS "Physician",
       p.position "Designation"
FROM physician p
LEFT JOIN trained_in t ON p.employeeid=t.physician
WHERE t.treatment IS NULL
ORDER BY employeeid;

Sample Output:

     Physician     |        Designation
-------------------+----------------------------
 John Dorian       | Staff Internist
 Elliot Reid       | Attending Physician
 Percival Cox      | Senior Attending Physician
 Bob Kelso         | Head Chief of Medicine
 Keith Dudemeister | MD Resident
 Molly Clock       | Attending Psychiatrist
(6 rows)

Practice Online


E R Diagram of Hospital Database:

E R Diagram: SQL Hospital Database.

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query in SQL to obtain the name of the physicians with department who are yet to be affiliated.
Next: Write a query in SQL to obtain the name of the patients with their physicians by whom they got their preliminary treatement.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming