简体   繁体   中英

How to merge two columns in DB2

How can I merge two columns in a table and duplicate the others? Here is a simple example of what I want to do:

Suppose I have this table:

   | C1 | C2 |
--------------
A1 | 1  | 2  |
--------------
A1 | 3  | 4  |
--------------
A2 | 5  | 6  |

I want to transform it to the following result:

   | C  |
---------
A1 | 1  |
---------
A1 | 2  |
---------
A1 | 3  |
---------
A1 | 4  |
---------
A2 | 5  |
---------
A2 | 6  |

Is there a way to do this in SQL DB2 ?

you can simply use a union all

select A, C1 as C from `table`
union all 
select A, C2 from `table`

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