w3resource
SQL exercises

SQL exercises on hospital Database: Find the name of the physicians who are the head of each department

SQL hospital Database: Exercise-3 with Solution

3. Write a query in SQL to obtain the name of the physicians who are the head of the department.

Sample table: physician


Sample table: department


Sample Solution:

SELECT d.name AS "Department",
       p.name AS "Physician"
FROM department d,
     physician p
WHERE d.head=p.employeeid;

Sample Output:

    Department    |  Physician
------------------+--------------
 General Medicine | Percival Cox
 Surgery          | John Wen
 Psychiatry       | Molly Clock
(3 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 find the name of the nurse who are the head of their department.
Next:Write a query in SQL to count the number of patients who booked an appointment with at least one physician.

What is the difficulty level of this exercise?



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