LoginSignup
4
3

More than 5 years have passed since last update.

SELECT文中で定数テーブルを作る方法がほしい

Posted at

テーブルを作らなくてもSELECT文の中で定数テーブルを書ければ便利だと思うんだけど、なんかお手軽な方法が見つからない。

定数SELECTをUNION ALLでくっつけていく、というのは思いついたけど、構文が野暮ったいような気が。。。

SELECT 1 as a, 2 as b, 3 as c
UNION ALL
SELECT 10, 20, 30
UNION ALL
SELECT 100, 200, 300
;
-- こうなる
+-----+-----+-----+
| a   | b   | c   |
+-----+-----+-----+
|   1 |   2 |   3 |
|  10 |  20 |  30 |
| 100 | 200 | 300 |
+-----+-----+-----+
3 rows in set (0.00 sec)

JSONみたいに書きたいんだけどなー。一時テーブルを作るのが正しいのかな。

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