Предположим, что у нас есть таблица 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 specialty LIKE 'java';
+----+-------------------+-----------+--------+
| id | name | specialty | salary |
+----+-------------------+-----------+--------+
| 1 | Eugene Suleimanov | Java | 2000 |
+----+-------------------+-----------+--------+
1 row in set (0.00 sec)
mysql> SELECT * FROM developers WHERE 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 <> 2000;
+----+------------------+------------+--------+
| id | name | specialty | salary |
+----+------------------+------------+--------+
| 2 | Peter Romanenko | C++ | 2500 |
| 3 | Asya Suleimanova | Javascript | 1500 |
+----+------------------+------------+--------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM developers WHERE salary = 2500;
+----+-----------------+-----------+--------+
| id | name | specialty | salary |
+----+-----------------+-----------+--------+
| 2 | Peter Romanenko | C++ | 2500 |
+----+-----------------+-----------+--------+
1 row in set (0.00 sec)
На этом мы заканчиваем обзор примеров использования операторов сравнения структурированного языка запросов SQL.