1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SQL基本

Posted at

テーブル:  シート
カラム:   行
レコード:  列
フィールド: 一つ一つの要素

160425_DBword_04.png

基本構文
select X(カラム名)
from Y(テーブル名)
where Z(条件式);

▶️Yテーブルから、Zの条件でXカラムを抽出する。

よく使う条件式
・order by (カラム名) desc(降順),asc(昇順)
select... from... order by...;
・where (カラム名) like '(フィールド名)%'; ←前方一致のワイルドカード
select... from... where ... like...;

複数のカラム条件 : AND演算子
select... from...
where (Aカラム) = 'C'
AND (Bカラム) = 'D';
 ▶️Aカラム=C かつ Bカラム=C 

同じカラムで複数条件
select... from...
where (Aカラム)
in('X', 'Y');
 ▶️Aカラム=XまたはY

重複したデータを省く
select distinct(Aカラム)
from...
 ▶️Aカラムから重複したデータを省く。

レコードを削除する
delete
from...
where (Aカラム) = 'X'
 ▶️Aカラム = X のレコードを削除する。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?