Skip to main content

Comparison Operators

This topic describes the comparison operators supported StoneDB.

OperatorDescription
=Equal operator
>Greater than operator
<Less than operator
>=Greater than or equal operator
<=Less than or equal operator
!=, <>Not equal operator
<=>NULL-safe equal operator
BETWEEN… AND…Whether a value is within a value range
INWhether a value is within a set of values
NOT INWhether a value is not within a set of values
LIKESimple pattern matching
regexpRegular expression
IS NULLNULL value test
IS NOT NULLNOT NULL value test

The following code provides an example of using each operator.

> select 2=3;
+-----+
| 2=3 |
+-----+
| 0 |
+-----+
1 row in set (0.00 sec)

> select 2>3;
+-----+
| 2>3 |
+-----+
| 0 |
+-----+
1 row in set (0.00 sec)

> select 2<3;
+-----+
| 2<3 |
+-----+
| 1 |
+-----+
1 row in set (0.00 sec)

> select 2>=3;
+------+
| 2>=3 |
+------+
| 0 |
+------+
1 row in set (0.00 sec)

> select 2<=3;
+------+
| 2<=3 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

> select 2<>3;
+------+
| 2<>3 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

> select 2<=>3;
+-------+
| 2<=>3 |
+-------+
| 0 |
+-------+
1 row in set (0.01 sec)

> select 5 between 1 and 10;
+--------------------+
| 5 between 1 and 10 |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)

> select 5 in (1,2,3,4,5);
+------------------+
| 5 in (1,2,3,4,5) |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)

> select 5 not in (1,2,3,4,5);
+----------------------+
| 5 not in (1,2,3,4,5) |
+----------------------+
| 0 |
+----------------------+
1 row in set (0.00 sec)

> select '12345' like '12%';
+--------------------+
| '12345' like '12%' |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)

> select 'beijing' REGEXP 'jing';
+-------------------------+
| 'beijing' REGEXP 'jing' |
+-------------------------+
| 1 |
+-------------------------+
1 row in set (0.00 sec)

> select 'beijing' REGEXP 'xi';
+-----------------------+
| 'beijing' REGEXP 'xi' |
+-----------------------+
| 0 |
+-----------------------+
1 row in set (0.00 sec)

> select 'a' is NULL;
+-------------+
| 'a' is NULL |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)

> select 'a' IS NOT NULL;
+-----------------+
| 'a' IS NOT NULL |
+-----------------+
| 1 |
+-----------------+
1 row in set (0.00 sec)