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: nurseemployeeid | 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:
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 Tree:
Practice Online
E R Diagram of 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.
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics