0
1

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 3 years have passed since last update.

SQL データ加工の基礎的な方法Ⅲ

Posted at

◆データを加工する(並べる)

ORDER BY 並べ替えたいカラム名 並べ方
「昇順」は「ASC」「降順」は「DESC」

例)
SELECT *
FROM purchases
ORDER BY price DESC;

WHEREと併用することも可能

SELECT *
FROM purchases
WHERE 条件
ORDER BY price DESC;

◆ある文字を含むデータを取得したい場合

例)
SELECT *
FROM purchases
WHERE name LIKE "%文字列%";

例2)
SELECT *
FROM purchases
WHERE name LIKE "プリン%";
プリンで始まる文字列

例3)
SELECT *
FROM purchases
WHERE name LIKE "%プリン";
プリンで終わる文字列

◆LIMIT 最大取得件数の設定

SELECT *
FROM purchases
WHERE 条件
LIMT 5

◆データを追加しよう
INSERT INTO students(id,name,course)
VALUES(4,"kate","java")

id部分は省略することができる

◆データの更新
UPDATE students
SET name = "jordan", course = "HTML" →指定するカラムを新し値にする
WHERE id = 6; →更新したいレコードを記載する

◆データを消す
DELETE FROM students
WHERE id = 6;

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?