SQL
SELECT NULL is essential for identifying missing or undefined values in specific columns and providing flexibility in SQL queries.
The basic syntax of the SELECT NULL
command is as follows:
SELECT NULL;
student_id | student_name | date_of_birth |
---|---|---|
1 | John Doe | 1990-05-15 |
2 | Jane Smith | NULL |
3 | Bob Johnson | 1992-09-08 |
To retrieve students with an unknown date of birth:
SELECT student_id, student_name
FROM students
WHERE date_of_birth IS NULL;
student_id | student_name |
---|---|
2 | Jane Smith |
On the flip side, what if you want to find students with a recorded date of birth? You can use a similar approach, swapping IS NULL
with IS NOT NULL
.
SELECT student_id, student_name
FROM students
WHERE date_of_birth IS NOT NULL;
student_id | student_name |
---|---|
1 | John Doe |
3 | Bob Johnson |