SQL NULL Tutorial
SQL NULL value represents a blank value in a table. NULL value is used for identifying any missing entries in a table.
One can use NOT NULL value to display table entries which are not NULL.
Syntax of NULL Value
SELECT column_name(s)
FROM table_name
Where column_name IS NULL;
SELECT column_name(s)
FROM table_name
Where column_name IS NOT NULL;
SQL NULL STATEMENT Example:
Database table “Employee”
Employee ID | Employee Name | Age | Gender | Location | Salary |
1001 | Henry | 54 | Male | New York | 100000 |
1002 | Tina | 36 | Female | Moscow | 80000 |
1003 | John | 24 | Male | 40000 | |
1004 | Mile | 31 | Male | London | 70000 |
1005 | Tara | 26 | Female | 50000 | |
1006 | Sohpie | 29 | Female | London | 60000 |
Note: "Location" column in the "Employee" table above is optional. Therefore, if one enters a data with no value for the "Location" column, the "Location" column will be saved with a NULL value.
Now if one wants to display the entries whose location is left blank, then here is a statement example.
SELECT * FROM Employee
WHERE Location IS NULL;
SQL NULL Statement Output:
The NULL statement will display the following results
Employee ID | Employee Name | Age | Gender | Location | Salary |
1003 | John | 24 | Male | 40000 | |
1005 | Tara | 26 | Female | 50000 |
SQL NOT NULL Statement
Now one wants to display the field entries whose location is not left blank, then here is a statement example.
SELECT * FROM Employee
WHERE Location IS NOT NULL;
SQL NOT NULL Statement Output:
The NOT NULL statement will display the following results
Employee ID | Employee Name | Age | Gender | Location | Salary |
1001 | Henry | 54 | Male | New York | 100000 |
1002 | Tina | 36 | Female | Moscow | 80000 |
1003 | John | 24 | Male | London | 40000 |
1006 | Sophie | 29 | Female | London | 60000 |