=
This page is part of MariaDB's Documentation.
The parent of this page is: SQL Operators for MariaDB Xpand
Topics on this page:
Overview
Equality with special treatment of NULL.
USAGE
value1 = value2
Value Name | Description |
---|---|
| The two values to compare |
DETAILS
The =
operator compares two values, returning 1
(true) if both values are equivalent, otherwise 0
(false).
If at least one value is a number, a numeric comparison is performed. Thus, a string value is converted into a number when paired with a numeric value.
When both values are strings, the comparison takes into account the current sort order, which might treat uppercase and lowercase letters as equivalent. If you need to ignore case, consider casting one of the input values to BINARY
.
A NULL
is returned if either value is NULL
.
The operator expression x = y
behaves in exactly the same manner as the function call EQ(x, y)
.
EXAMPLES
SELECT 42 = 42, 1 = 0, NULL = NULL;
+---------+-------+-------------+
| 42 = 42 | 1 = 0 | NULL = NULL |
+---------+-------+-------------+
| 1 | 0 | NULL |
+---------+-------+-------------+
SELECT 99 = 123,
PI() = 3.141592653589793 AS pi_eq;
+----------+-------+
| 99 = 123 | pi_eq |
+----------+-------+
| 0 | 1 |
+----------+-------+
-- Disable strict mode or the comparison might throw an error
SET sql_mode = '';
SELECT 99 = '99a', 'abc' = 0;
+------------+-----------+
| 99 = '99a' | 'abc' = 0 |
+------------+-----------+
| 1 | 1 |
+------------+-----------+
CREATE TABLE eq_example (
description VARCHAR(20),
example INT
);
INSERT INTO eq_example VALUES
('Everything', 42),
('Dalmations', 101),
('Agent', 99),
('B. Doz.', 13),
('CPU', 64);
SELECT *
FROM eq_example
WHERE example = 101 OR description = 'B. Doz.';
+-------------+---------+
| description | example |
+-------------+---------+
| Dalmations | 101 |
| B. Doz. | 13 |
+-------------+---------+