How to merge two columns in sql and display it into a separate record

后端 未结 3 542
臣服心动
臣服心动 2021-01-26 08:49

I have this table

Column1|Column2
1       2
3       4

I want to merge two columns and make them appear like this

 NewColumn
 1         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-26 09:08

    The keyword you're looking for is UNION:

    SELECT column 1 AS newColumn
    FROM...
    UNION
    SELECT column2 AS newColumn
    FROM...
    ORDER BY newColumn
    

    This of course gets unwieldy if you need to combine multiple columns - ideally avoid having to do it by storing data as raw as possible and aggregating instead.

提交回复
热议问题