w3resource
SQL exercises

SQL exercises on hospital Database: Find the names of all the nurses who have ever been on call for room 122

SQL hospital Database: Exercise-35 with Solution

35. Write a query in SQL to obtain the names of all the nurses who have ever been on call for room 122.

Sample table: nurse


Sample table: on_call


Sample table: room

Sample Solution:

SELECT n.name
FROM nurse n
WHERE employeeid IN
    ( SELECT oc.nurse
     FROM on_call oc,
          room r
     WHERE oc.blockfloor = r.blockfloor
       AND oc.blockcode = r.blockcode
       AND r.roomnumber = 122 );

Sample Output:

      name
-----------------
 Laverne Roberts
 Paul Flowers
(2 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.

What is the difficulty level of this exercise?



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