SQL NULL VALUES

To check weather there is a null value or not, we use IS NULL or IS NOT NULL operators.

IS NULL : It is a condition used to select rows where the specific field is NULL. 

Syntax:

SELECT * FROM table_name
WHERE column_name IS NULL;

STUDENTS DEMO TABLE



Data

Roll_NO Name Total_Marks Phone_Number
1 Arun NULL NULL
2 Rahul 68 2147483647
3 Nazim 75 785764
4 Alex 65 NULL
5 Pyush 97 NULL
6 Dev 67 69483647

Example: To select the rows where the Phone_Number is NULL

SELECT * FROM students
WHERE Phone_Number IS NULL;

The resultant table will be as shown below:



Data

Roll_NO Name Total_Marks Phone_Number
1 Arun NULL NULL
4 Alex 65 NULL
5 Pyush 97 NULL

IS NOT NULL : It is a condition used to select rows where the specific field is NOT NULL. 

Syntax:

SELECT * FROM table_name
WHERE column_name IS NOT NULL;

STUDENTS DEMO TABLE



Data

Roll_NO Name Total_Marks Phone_Number
1 Arun NULL NULL
2 Rahul 68 2147483647
3 Nazim 75 785764
4 Alex 65 NULL
5 Pyush 97 NULL
6 Dev 67 69483647

Example: To select the rows where the Phone_Number is NOT NULL

SELECT * FROM students
WHERE Phone_Number IS NULL;

The resultant table will be as shown below:



Data

Roll_NO Name Total_Marks Phone_Number
2 Rahul 68 2147483647
3 Nazim 75 785764
6 Dev 67 69483647