引き続き where 句の書き方を学習していきましょう。ここでは between 演算子による条件の指定方法を取り上げます。
between 演算子によって、カラムに対して値を範囲指定できます。具体的には between 演算子のあとに範囲の下限をとり and のあとに範囲の上限を指定します。
where 列名 between データ and データ
between 演算子を使うことで and 演算子による条件指定をシンプルに表現できます。次のSQLでは courses テーブルから learning_time 列の値が 30 から 50 の間に含まれるものを検索します。

MariaDB [eldb]> select * from courses
-> where learning_time between 30 and 50;
+----+--------------+---------------+-------------+
| id | title | learning_time | category_id |
+----+--------------+---------------+-------------+
| 1 | PHP Basic | 30 | 1 |
| 2 | PHP Database | 50 | 1 |
| 3 | Python Basic | 40 | 1 |
| 4 | Web Design | 50 | 2 |
+----+--------------+---------------+-------------+
4 rows in set (0.00 sec)
MariaDB [eldb]>
between 30 and 50とした場合、検索結果に30や50も含まれる点に注意してください。つまりこの場合のbetween演算子は30以上、かつ50以下のように動作します。
(参考) and 演算子による範囲指定の場合
さきほどと同様のSQLを and 演算子で記述すると次のようになります。
MariaDB [eldb]> select * from courses
-> where learning_time >= 30 and learning_time <= 50;
+----+--------------+---------------+-------------+
| id | title | learning_time | category_id |
+----+--------------+---------------+-------------+
| 1 | PHP Basic | 30 | 1 |
| 2 | PHP Database | 50 | 1 |
| 3 | Python Basic | 40 | 1 |
| 4 | Web Design | 50 | 2 |
+----+--------------+---------------+-------------+
4 rows in set (0.00 sec)
MariaDB [eldb]>
このようなケースでは between 演算子を使う方が短いコードで表現できます。