5
4

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.

WITH句について

Last updated at Posted at 2019-04-23

こちらの記事から
https://docs.aws.amazon.com/ja_jp/redshift/latest/dg/r_WITH_clause.html

WITH句とは

サブクエリでテーブルを定義するもの

  • SELECTより先に評価される
  • 各サブクエリは、ビュー定義に似ている一時テーブルを定義する
  • 一時テーブルはFROM句内で参照可能

構文

WITH テーブル名 AS (サブクエリ)

使用可能なSQLステートメント

  • SELECT (SELECT ステートメント内のサブクエリを含む)
  • SELECT INTO
  • CREATE TABLE AS
  • CREATE VIEW
  • DECLARE
  • EXPLAIN
  • INSERT INTO...SELECT
  • PREPARE
  • (WHERE 句サブクエリ内の) UPDATE

WITH tmp_table AS (SELECT * FROM exist_table)
SELECT * FROM tmp_table;

ポイント

  • 固有の目的に合わせたテーブル構造のデータから更にデータを抽出したい時などに使える
  • 抽出した結果を別テーブルとして作成したい時などに使える
  • WITH句のサブクエリ内で、別のWITH句を指定することはできない

参考URL

雑感

MySQLは8から使える

5
4
1

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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?