BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

SQL NULL Check in Where clause – IS NULL and IS NOT NULL

Last Updated: December 2, 2018 by Chaitanya Singh | Filed Under: SQL

In SQL Where clause tutorial, we learned how to use comparison operators such as =, <, > etc in where clause for conditions. However when a column (field) of table has null values then such operators do not work on those columns, in such case we have to use IS NULL & IS NOT NULL operators for the null check. In this guide, we will learn how to deal with null values in SQL.

How to check for null values in SQL

We cannot use comparison operators such as =, <, > etc on null values because the result is undefined. To check for null values we can use IS NULL and IS NOT NULL operators. Lets see the syntax of these operators.

IS NULL Syntax

Null check:

SELECT column_name1, column_name2, column_name3, ...
FROM table_name
WHERE column_nameN IS NULL;

IS NOT NULL Syntax

Not Null check:

SELECT column_name1, column_name2, column_name3, ...
FROM table_name
WHERE column_nameN IS NOT NULL;

SQL IS NULL or empty check Example

Table: Employees

EmployeeName   EmployeeAge  EmployeePhoneNo  EmployeeAddress
------------   -----------  ---------------  ---------------
Cindi           34           95XXXXXXX8        Noida
Linda           35                             Agra
Shaun           33           75XXXXXXX4        Delhi
Timmy           34                             Noida
Pappu           36                             Noida

The following SQL statement will fetch the EmployeeName & EmployeeAddress details of employees where the EmployeePhoneNo column has null value.

SELECT EmployeeName, EmployeeAddress
FROM Employees
WHERE EmployeePhoneNo IS NULL;

Result:

EmployeeName   EmployeeAddress
------------   ---------------
Linda           Agra
Timmy           Noida
Pappu           Noida

SQL IS NOT NULL in where clause Example

Lets take the same example that we have seen above. In this example, we will check for the not null values.
Table: Employees

EmployeeName   EmployeeAge  EmployeePhoneNo  EmployeeAddress
------------   -----------  ---------------  ---------------
Cindi           34           95XXXXXXX8        Noida
Linda           35                             Agra
Shaun           33           75XXXXXXX4        Delhi
Timmy           34                             Noida
Pappu           36                             Noida

The following SQL statement will fetch the EmployeeName & EmployeeAddress details of employees where the value of EmployeePhoneNo column is not null.

SELECT EmployeeName, EmployeeAddress
FROM Employees
WHERE EmployeePhoneNo IS NOT NULL;

Result:

EmployeeName   EmployeeAddress
------------   ---------------
Cindi           Noida
Shaun           Delhi

Top Related Articles:

  1. DELETE Query in SQL
  2. Introduction to SQL
  3. SQL Syntax
  4. SQL – DROP Table Statement to delete the entire table
  5. SQL AND, OR and NOT Operators with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

SQL Tutorial

  • SQL Tutorial
  • SQL Introduction
  • SQL Syntax
  • SQL Data Types

SQL Database

  • SQL CREATE DB
  • SQL DROP DB
  • SQL Rename DB
  • SQL USE DB

SQL Queries

  • SQL Select
  • SQL Select Distinct
  • SQL Select Count
  • SQL Select Top
  • SQL Where
  • SQL AND, OR & NOT
  • SQL Order By
  • SQL Insert Into
  • SQL Insert Into SELECT
  • SQL Select Random
  • SQL Alias
  • SQL NULL Check
  • SQL Update
  • SQL Delete
  • SQL MIN, MAX
  • SQL SUM
  • SQL AVG

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap