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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.