Home » SQL

SQL query to find fields with NULL values

Here, we are going to learn how to find fields with NULL values? How to get records whose specific column has the NULL values?
Submitted by Abhishek Goel, on April 26, 2020

In SQL NULL values are those fields that do not contain any specific value.

But we should remember that the NULL value is different from the zero value or just space value (" "). Field with NULL value is the field that is left blank at the time of database creation.

Let us consider the following dataset and try to find out the NULL field present in it.

Table: Employee

EmpIDFirstNameLastNameDesignSalary
101RaviGuptaPresident5000
202KishanSainiManager4000
303UshaMittalSr. Analyst3500
404MonnieSaxenaNULL3000
505MaheshAggarwalDeveloper4500
606ParveenGargClerk3000
707MukulSharmaNULL2500
808BhaveshJoonSalesman2500

Testing of NULL value is not possible with the help of >, <, = signs rather we have to use IS NULL or NOT NULL operators.

Let us first talk about the syntax.

Syntax:

    SELECT column_names
    FROM table_name
    WHERE column_name IS NULL;

Now let's work upon the demo database provided above

SQL Query:

SELECT FirstName, LastName, Design
FROM Employee
WHERE Design IS NULL;

Output:

FirstNameLastNameDesign
MonnieSaxenaNULL
MukulSharmaNULL

Note: Always remember to use the IS NULL operator, to check for Null Fields in the Table of the database.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.