xjdeng
xjdeng

Reputation: 49

SQLite: Merging the contents of 2 columns into 1?

How do I merge the contents of two columns into one in SQLite? I'm not looking to union 2 columns, I just want SQLite to automatically copy the entire contents of two columns and dump them (in any order) into a single column. For example, suppose I have the following table:

Table1:

Column1:      Column2:

Red,          Yellow
Green,        Red
Blue,         Gold
Purple,       Green
Black,        White

And this is the desired result:

Red
Green
Blue
Purple
Black
Yellow
Red
Gold
Green
White

What's the simplest SQLite query that'll get to the desired result?

I tried the following: Select Column1 || Column2 FROM Table1;

But I got the undesired result:

RedYellow
GreenRed
BlueGold
PurpleGreen
BlackWhite

Upvotes: 0

Views: 82

Answers (1)

user2941651
user2941651

Reputation:

I think that UNION ALL should give you the result:

Select Column1 AS Column_1_2 FROM Table1
UNION ALL
Select Column2 AS Column_1_2 FROM Table1;

Upvotes: 0

Related Questions