Skip to content
Advertisement

How to combine two columns from the tail of a column?

What I am going to do is:

I have two columns, A and B, I need to add b to the tail position of A, anyone knows how to do that?

Original dataset:

A  B
----
1  6
2  7
3  8
4  9
5  0

What I need is:

A+B
----
1
2
3
4
5
6
7
8
9
0

Advertisement

Answer

SELECT a FROM yourtable
UNION ALL
SELECT b FROM yourtable

But do note, datasets in SQL are implicitly unordered.

Unless you add another column, by which you can order the results, they’re not added to the tail, they’re just unioned into a new unordered set.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement