IS NOT DISTINCT FROM Operator
Overview
The IS NOT DISTINCT FROM
operator is a counterpart to IS DISTINCT FROM
.
It compares two values, treating them as equal even when they are both NULL
. This operator returns TRUE
if the two values are the same, including the case where both values are NULL
and FALSE
if they are different.
Syntax
The syntax for the operator is as follows:
Where:
-
value1
is the first value for comparison. -
value2
is the second value for comparison.
Examples
Case #1: Basic Usage
Consider the following example where we compare two values:
Example 1
The above query will return the following output:
Example 2
The above query will return the following output:
Example 3
The above query will return the following output:
Case #2: Comparing NULL Values
In this example, we’ll compare NULL values using the IS NOT DISTINCT FROM operator:
Example 1
The above query will return the following output:
Example 2
The above query will return the following output:
Case #3: Analyzing Data Completeness
Suppose we have a table named customer_contacts that stores customer contact information.
Our objective is to retrieve records from this table where an email address or a phone number is available for contacting the customers.
In this query, we retrieve all rows from the customer_contacts table
where the email and phone are NULL. We can conclude that the customer with customer_id 104
has no phone number or email address.