SELECT文の基本的な実行手順
likeとワイルドカード
%="ほにゃほにゃ"
- sqlという語句を含むデータ
.sql
where カラム like "%sql%";
- 末尾がsqlという語句のデータ
.sql
where カラム like "%sql";
- 先頭がsqlという語句のデータ
ex.sql
where カラム like "sql%";
not演算子
ex.sql
where not name = "ポチ";
null
これだけちょっと書き方ちがうので注意
- nullではないデータの取得
ex.sql
where price is not null
- nullのデータの取得
ex.sql
where price is null
order by
priceカラムを降順に並び替えて上位5件だけ表示
ex.sql
SELECT *
FROM purchases
order by price desc
limit 5;
and
ex.sql
SELECT *
FROM purchases
where category = "食費"
and character_name = "ひつじ仙人";
