0% found this document useful (0 votes)
86 views

SQL NULL Values: What Is A NULL Value?

Uploaded by

jeffa123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

SQL NULL Values: What Is A NULL Value?

Uploaded by

jeffa123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL 

NULL Values
❮ PreviousNext ❯

What is a NULL Value?


A field with a NULL value is a field with no value.

If a field in a table is optional, it is possible to insert a new record or update a


record without adding a value to this field. Then, the field will be saved with a
NULL value.

Note: A NULL value is different from a zero value or a field that contains
spaces. A field with a NULL value is one that has been left blank during record
creation!

How to Test for NULL Values?


It is not possible to test for NULL values with comparison operators, such as =,
<, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.

IS NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;

IS NOT NULL Syntax


SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
Demo Database
Below is a selection from the "Customers" table in the Northwind sample
database:

CustomerID CustomerName ContactName Address City P


e

1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 1

2 Ana Trujillo Emparedados y Ana Trujillo Avda. de la Constitución México 0


helados 2222 D.F.

3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México 0


D.F.

4 Around the Horn Thomas Hardy 120 Hanover Sq. London W

5 Berglunds snabbköp Christina Berguvsvägen 8 Luleå S


Berglund

The IS NULL Operator


The IS NULL operator is used to test for empty values (NULL values).

The following SQL lists all customers with a NULL value in the "Address" field:

Example
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;
Try it Yourself »
Tip: Always use IS NULL to look for NULL values.

The IS NOT NULL Operator


The IS NOT NULL operator is used to test for non-empty values (NOT NULL
values).

The following SQL lists all customers with a value in the "Address" field:

Example
SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NOT NULL;
Try it Yourself »

Test Yourself With Exercises


Exercise:
Select all records from the Customers where
the PostalCode column is empty.

SELECT * FROM Customers


WHERE ;
Submit Answer »

Start the Exercise

❮ PreviousNext ❯

COLOR PICKER

LIKE US
  

Get certified
by completing
a course today!

w3schoolsCERTIFIED.2021
Get started

CODE GAME

Play Game

REPORT ERROR
FORUM
ABOUT
SHOP

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Web Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »

W3Schools is optimized for learning and training. Examples might be simplified


to improve reading and learning. Tutorials, references, and examples are
constantly reviewed to avoid errors, but we cannot warrant full correctness of
all content. While using W3Schools, you agree to have read and accepted
our terms of use, cookie and privacy policy.

Copyright 1999-2021 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by W3.CSS.

You might also like