Burhan Shakir Burhan Shakir - 1 year ago 111
SQL Question

Combining two columns in SQL

I want to combine two columns in such a way that the second column gets added below the first column.
For eg:

Col 1: A B C
Col 2: D E F

Result :

Col : A B C D E F

Answer Source

Do a UNION ALL to get the two columns as one single column:

select col1 from tablename
select col2 from tablename

If you absolutely want col1 values before col2 values, wrap it up in a derived table and add an ORDER BY:

select col from
    select col1 as col, 1 as ob from tablename
    select col2, 2 as ob from tablename
) dt
order by ob