w3resource

SQL Exercise: List the nurses who are yet to be registered

SQL hospital Database: Exercise-1 with Solution

1. From the following table, write a SQL query to find out which nurses have not yet been registered. Return all the fields of nurse table.

Sample table: nurse
 employeeid |      name       |  position  | registered |    ssn
------------+-----------------+------------+------------+-----------
        101 | Carla Espinosa  | Head Nurse | t          | 111111110
        102 | Laverne Roberts | Nurse      | t          | 222222220
        103 | Paul Flowers    | Nurse      | f          | 333333330

Sample Solution:

SELECT *
FROM nurse
WHERE registered='false';

Sample Output:

  employeeid |     name     | position | registered |    ssn
 ------------+--------------+----------+------------+-----------
         103 | Paul Flowers | Nurse    | f          | 333333330
 (1 row)

Explanation:

The given query in SQL that retrieves all rows from the nurse table where the value of the registered column is 'false'.

The WHERE clause filters the results and returns only the rows where the value of the registered column is 'false'.

Pictorial presentation:

Find all the information of the nurses who are yet to be registered

Alternative Solution:

Using NOT Operator:


SELECT *
FROM nurse
WHERE NOT registered;

Explanation:

This query uses a NOT operator that negates the value of registered, effectively finding the nurses who are not registered.

Relational Algebra Expression:

Relational Algebra Expression: Find all the information of the nurses who are yet to be registered.

Relational Algebra Tree:

Relational Algebra Tree: Find all the information of the nurses who are yet to be registered.

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 SQL Exercise: SQL Hospital Database - Exercises, Practice, Solution
Next SQL Exercise: Find the nurse who are the head of their department.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/hospital-database-exercise/sql-exercise-hospital-database-1.php