ID EN
Comparison Functions and Operators

<=>

MySQL 8.4

NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

Syntax

MYSQL
SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
1, 1, 0
SELECT 1 = 1, NULL = NULL, 1 = NULL;
1, NULL, NULL

Examples

Example

The operator is equivalent to the standard SQL IS NOT DISTINCT FROM operator.

MYSQL
SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
1, 1, 0
SELECT 1 = 1, NULL = NULL, 1 = NULL;
1, NULL, NULL
Example 2

For row comparisons, (a, b) (x, y) is equivalent to:

MYSQL
(a <=> x) AND (b <=> y)