SQL NULL-SAFE EQUAL
Anonymous contributor
Published Oct 7, 2024
Contribute to Docs
In SQL, the NULL-SAFE EQUAL operator performs an equality comparison like the = operator. However, it can also accept NULL values and never returns NULL, instead always returning TRUE or FALSE. It uses the logic of an XNOR gate to determine the value returned. It is written as <=>.
This operator is useful in cases where XNOR-like logic is required for comparisons that can accept NULL values and always return TRUE or FALSE.
Syntax
SELECT column1
FROM table
WHERE column1 <=> value;
Note: The syntax can vary across different SQL flavors. In PostgreSQL, the operator is written as
IS NOT DISTINCT FROM. In MariaDB/MySQL, it is written as<=>. Also, in SQLite, it is written asIS.
Example
The following example demonstrates the usage of the NULL-SAFE EQUAL operator:
SELECT NULL <=> 1, NULL <=> NULL, 3 <=> NULL, 2 <=> 2;
The above query returns the following result:
0, 1, 0, 1
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.18 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours