2011-05-15
何かと利用頻度の多い「SELECT」でのデータ抽出条件式をメモ。
ソート(並べ替え)は「order by」(order by フィールド名)
抽出件数を制限する場合は「limit」(limit 0, 10)を使用
■[where 条件式]
演算子 | 説明 | 例 |
---|---|---|
= | 等しければ | id = 1 |
<>!= | 等しくなければ | id <> 1 または id != 1 |
> | 大きければ | id > 10 |
>= | 以上なら | id >= 10 |
< | 小さければ | id < 10 |
<= | 以下なら | id <= 10 |
is null | nullなら | zip is null |
is not null | nullでなければ | zip is not null |
in | どれかに等しければ | id in ( 1, 2, 3 ) |
between a1 and a2 | a1からa2の間なら | id between 1 and 10 |
like | あいまい検索 | handle_name like '%wind%' ※windが含まれていれば真。 |
and | 二つの条件が真なら | id = 1 and zip is null |
or | どちらかの条件が真なら | id = 1 or zip is null |
not | 条件の反転 | not( id = 1 ) |