5.テーブルからデータを取り出す

■テーブルからデータを取り出す
mysql> select * from テーブル名;

■条件を使って取り出す(比較演算子)
mysql> select * from テーブル名 where 条件カラム名=値など);
例)mysql> select * from ex_table where ex_c=1;

※比較演算子
>
<
>=
<=
=
<>(!=)

■条件を使って取り出す(論理演算子)
mysql> select * from テーブル名 where 条件 and 条件;
例)mysql> select * from ex_table where ex_c=3 and ex_c_2='aaa';

※論理演算子
[ and](&&)
[or](||)
[not()]

■条件を使って取り出す(like / not like)
mysql> select * from テーブル名 where カラム名 like "%";
例)mysql> select * from ex_table where ex_c like "aaa%"
※%はワイルドカード。上記なら前方一致。
※not like で否定形

■条件を使って取り出す(is null / not null)
mysql> select * from テーブル名 where カラム名 is null;
例)mysql> select * from ex_table where ex_c is null;
※not null で非定型(データが存在するデータの検索)

戻る | CGI'sトップへ戻る