Предположим, что у нас есть таблица developers:
mysql> select * from developers;
+----+-------------------+------------+--------+
| id | name | specialty | salary |
+----+-------------------+------------+--------+
| 1 | Eugene Suleimanov | Java | 2000 |
| 2 | Peter Romanenko | C++ | 2500 |
| 3 | Asya Suleimanova | Javascript | 1500 |
| 4 | Andrei Komarov | Php | 2000 |
+----+-------------------+------------+--------+
4 rows in set (0.00 sec)
Ниже приведены несколько примеров использования операторов сравнения для данной таблицы:
mysql> select * from developers where salary >= 2000 and specialty like 'java';
+----+-------------------+-----------+--------+
| id | name | specialty | salary |
+----+-------------------+-----------+--------+
| 1 | Eugene Suleimanov | Java | 2000 |
+----+-------------------+-----------+--------+
1 row in set (0.00 sec)
mysql> select * from developers where specialty like 'C++' or salary >= 2000;
+----+-------------------+-----------+--------+
| id | name | specialty | salary |
+----+-------------------+-----------+--------+
| 1 | Eugene Suleimanov | Java | 2000 |
| 2 | Peter Romanenko | C++ | 2500 |
| 4 | Andrei Komarov | Php | 2000 |
+----+-------------------+-----------+--------+
3 rows in set (0.00 sec)
mysql> select * from developers where salary between 2000 and 3000;
+----+-------------------+-----------+--------+
| id | name | specialty | salary |
+----+-------------------+-----------+--------+
| 1 | Eugene Suleimanov | Java | 2000 |
| 2 | Peter Romanenko | C++ | 2500 |
| 4 | Andrei Komarov | Php | 2000 |
+----+-------------------+-----------+--------+
3 rows in set (0.00 sec)
На этом мы заканчиваем обзор примеров использования логических операторов языка SQL.