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

SQLメモ

Last updated at Posted at 2024-01-08

SELECT

LIKE句

完全一致と部分一致

完全一致

SELECT カラム名 FROM テーブル名 WHERE カラム名 LIKE '検索文字';

検索文字と完全に一致したデータのみ表示される。

部分一致

ワイルドカード文字 意味
% 0文字以上の任意の文字列
- 任意の1文字
SELECT * FROM poker_hand_probability WHERE name LIKE '%A';
/*
AAのレコードがヒット
________________
id |name | probability
1  |AA  | 85.3%
________________
*/


SELECT * FROM  WHERE name LIKE 'A%';
/*
Axo、Axsのレコードがヒット
________________
id |name | probability
1  |A2o  | 54.6%
2  |A3o  | 55.6%
2  |A4o  | 56.4%
________________
*/


SELECT * FROM  WHERE name LIKE 'A_';
/*
AAのレコードがヒット
________________
id |name | probability
1  |AA  | 85.3%
________________
*/

ORDER BY句

SELECT カラム名 FROM テーブル名 ORDER BY 基準にしたいカラム名 [ASC または DESC];

ASCが降順、DESCが昇順でデフォルトはASC

LIMIT句

SELECT カラム名 FROM テーブル名 LIMIT 取得したい行数;

リリース時に書き込みが上手くいってるか確認する時はこんな感じでやってる。

select * from --- order by id desc limit 30;

BETWEEN句

SELECT カラム名 FROM テーブル名 WHERE created_at BETWEEN "2024-01-01 15:00:00" AND "2024-01-02 14:59:59";

IN句

SELECT カラム名 FROM テーブル名 WHERE name IN("山田","田中");

TRUNCATE

TRUNCATE TABLE テーブル名 ;
0
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
0
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?