1
0

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 1 year has passed since last update.

常用のmySQLステートメント

Last updated at Posted at 2022-03-15

常用のmySQLステートメント

データを追加するmySQLステートメント

INSERT INTO dish
(dish_name,
price,
pic_path,
status,
category_id,
created,
updated,
buy_count)
VALUES(?,?,?,?,?,?,?,?)

削除するのステートメント(論理削除)

UPDATE dish SET status = 0 WHERE id = ?

更新するのステートメント

UPDATE dish_category 
SET dish_category_name = ?,
dish_category_des = ?,
updated = ? 
WHERE id = ? 
AND status = 1

マルチテーブル共同クエリ(Multi-table)

マルチテーブルのデータをクエリする1つのmySQLステートメント
1.外部結合:左外部結合and右外部結合
2.内部結合
3.完全結合

テーブルを共同クエリ、ページネーション(pagination)を実行します

SELECT a.id,
a.dish_name,
a.price,
a.pic_path,
a.buy_count,a.created,
a.updated,
b.dish_category_name
-- スペースとは名前を変更することを意味します
FROM dish a 
INNER JOIN dish_category b ON a.category_id = b.id 
WHERE a.status =1 AND b.status = 1
LIMIT 7,7

ページの総数を計算します

SELECT COUNT(*)
FROM dish a 
INNER JOIN dish_category b ON a.category_id = b.id 
WHERE a.status =1 AND b.status = 1
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?