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

【SQL】メモ3(テンポラリテーブル作成(CREATE TEMPORARY TABLE ))

Last updated at Posted at 2020-01-31

###0.目的
SQL忘却防止のため

###1.SELECT結果からテンポラリテーブルを作る
※複数テーブルを扱うときは、テーブル名.列名とすると
長くなるし扱いにくいため
FROM句でテーブル名 エイリアス名とすると
エイリアス名でアクセスできて便利。

-- SELECT結果を代入
CREATE TEMPORARY TABLE tmp_nohibrid as
 SELECT T1.id,T1.dname0,T1.type0 
 FROM tbl_dino T1
 WHERE T1.n_src1=0 and T1.n_src2=0;

###2.型指定してテーブルを作成してから、データを挿入する

-- 型指定して作成
CREATE TEMPORARY TABLE tbl_nohibrid
 (id INTEGER
,type0 TEXT
,dname0 TEXT
);

INSERT INTO tbl_nohibrid(id,type0,dname0)
 SELECT T1.id,T1.type0,T1.dname0
 FROM tbl_dino T1
 WHERE T1.n_src1=0 AND T1.n_src2=0;
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?