SQL NULL Values

A field with no value is known as a NULL value.It is possible that a new record is inserted into the table without adding a value to the column, then that field will be referred to as NULL value.

IS NULL Syntax :

The syntax of the IS NULL statement is −

SELECT column-names
FROM table-name
WHERE column-name IS NULL;



IS NOT NULL Syntax :

The syntax of the IS NOT NULL statement is −

SELECT column-names
FROM table-name
WHERE column-name IS NOT NULL;



NULL Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai null
3 Reyansh 28 null 35000
4 Muhammad 24 null 50000
5 Sai null Mumbai 27000


TEST CASE 1 :- The following code is an example, which would fetch the (CustomerName, Age, Address )lists all Customer from Customer table where Address is NULL.

SELECT CustomerName, Age, Address
FROM Customer
WHERE Address IS NULL;


The result for the respective sql query is as follows −

CustomerName Age Address
Reyansh 28 null
Muhammad 24 null



TEST CASE 2:- The following code is an example, which would fetch the (CustomerName, Age, Address )lists all Customer from Customer table where Address IS NOT NULL.

SELECT CustomerName, Age, Address
FROM Customer
WHERE Address IS NOT NULL;


The result for the respective sql query is as follows −

CustomerName Age Address
Aarav 28 Udaipur
Vivaan 25 Mumbai
Sai null Mumbai





Visit :


Discussion



* You must be logged in to add comment.