下面為 users資料表
id | name | gender | age
------------- | -------------
1 | Amy | female | 18
2 | John | male | 54
3 | David | male | 32
4 | Joyce | female |44
5 | David | male | 10
6 | Iris |female | 10
in / between / like 都與 SQL where 連用,進階的搜尋語法。
in:取出指定的資料,各條件之間以分號區隔。
SELECT * FROM users WHERE age in(18,10,32);
SELECT * FROM users WHERE name in('Iris','Amy');
not in:和in判斷相反,取得所有非指定條件的資料。
SELECT * FROM users WHERE name not in('Iris','Amy');
between:取出特定範圍內連續資料
SELECT * FROM users WHERE age between 10 and 30;
not between:和between判斷相反,取得此範圍外的所有資料
SELECT * FROM users WHERE age not between 10 and 30;
like:取得引號(' ')內相符的資料,%代表篩選時可以是任意值
SELECT * FROM users WHERE name like 'Jo%';
not like:和like判斷相反,取得所有不相符的資料
SELECT * FROM users WHERE name not like 'Jo%';