In This Article You Will Know About SQL Null Values.
SQL Null Values– Before moving ahead, let’s know a bit about SQL INSERT INTO.
Table of Contents
Null value
A null value is a value that contains no value.
Note: A value containing zero and space as a value is not considered a null value.
Test Null Value
Since it is impossible to check null value through comparison operators, use the ‘IS NULL’ and ‘IS NOT NULL’ statements.
Example Database
Below is the example of a database table named “details.”
Id | Name | Class | section_id |
1 | Alex | 5 | 1 |
2 | Rolex | 6 | 2 |
3 | Salex | 7 | 2 |
4 | Lelex | 8 | 3 |
5 | Kelex | 9 | 5 |
IS NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
IS NULL Example
Example: Use ‘IS NULL’ statement to check if ‘Name’ column has null or empty value.
SELECT Name FROM details
WHERE Name IS NULL;
Example: Use ‘IS NULL’ statement to check if ‘Class’ column has null or empty value.
SELECT Class FROM details
WHERE Class IS NULL;
Example: Use ‘IS NULL’ statement to check if ‘Name’, ‘Class’, and ‘section_id’ columns have null value.
SELECT Name, Class, section_id
FROM details
WHERE Name, Class, section_id IS NULL;
IS NOT NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
IS NOT NULL Example
Example: Use ‘IS NOT NULL’ statement to check if ‘Name’ column has null or empty value.
SELECT Name FROM details
WHERE Name IS NOT NULL;
Example: Use ‘IS NOT NULL’ statement to check if ‘Class’ column has null or empty value.
SELECT Class FROM details
WHERE Class IS NOT NULL;
Example: Use ‘IS NOT NULL’ statement to check if ‘Name’, ‘Class’, and ‘section_id’ columns have null value.
SELECT Name, Class, section_id
FROM details
WHERE Name, Class, section_id IS NOT NULL;
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.
Connect on: