简体   繁体   English

将一个表的每一列作为一行插入到另一个表中

[英]Insert each column of one table as a row in another table

I have one table with the following columns:我有一张包含以下列的表格:

c1, c2, c3, c4, c5

And another table with the following columns:另一个包含以下列的表:

id, column_info

...there are some other columns but here's the main problem. ...还有其他一些专栏,但这是主要问题。

For each column in table 1, I'd like to insert a row in table 2, like this:对于表 1 中的每一列,我想在表 2 中插入一行,如下所示:

id | column_info
---|------------
 1 | c1
 2 | c2
 3 | c3
 4 | c4
 5 | c5

Is this possible as an SQL statement?这可能作为 SQL 声明吗?

INSERT INTO Some_Table (id, column_info)
SELECT id, c1 UNION ALL
SELECT id, c2 UNION ALL
SELECT id, c3 UNION ALL
SELECT id, c4 UNION ALL
SELECT id, c5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM