简体   繁体   中英

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:

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

Is this possible as an SQL statement?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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