user123123123 user123123123 - 5 months ago 16
SQL Question

vertical merge of two columns into a single one

I have three columns as in the below image, and I would like to merge the two columns

values1
and
values2
into a single one. What is the SQL code to do it?

enter image description here

Answer

Try a UNION query:

SELECT nouns, values1 FROM yourTable
UNION ALL
(
    SELECT NULL, values2 FROM yourTable
)

Demo here:

SQLFiddle

Update:

You could also use the nouns column instead of filling with NULL, e.g.

SELECT nouns, values1 FROM yourTable
UNION ALL
(
    SELECT nouns, values2 FROM yourTable
)