IS DISTINCT FROM Operator
The IS DISTINCT FROM operator compares two values, considering them distinct even when both are NULL. It returns TRUE if the two values are different and FALSE if they are the same, including the case where both values are NULL.
The syntax for the operator is as follows:
Where:
- value1 is the first value for comparison.
- value2 is the second value for comparison.
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:
In this example, we'll compare NULL values using the IS DISTINCT FROM operator:
Example 1
The above query will return the following output:
Example 2
The above query will return the following output:
Suppose we have a table named inventory_changes that tracks changes in the quantities of products in a warehouse. The table has the following structure:
We want to retrieve records where the change quantity is distinct from zero. In this scenario, the IS DISTINCT FROM operator can be used.
The result of the query will not include the 0 values as shown below:

