Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge two columns into one column and get unique

I have two columns in a table. I need to merge these two columns into 1 column, while making sure all the values in the resulting column are unique (no repetition of the IDs) ex:

ChildCard    PrimaryCard
123456          123456
123450          123456
123446          123446
123456          123446
156456          155456
157456          155456
121290          124290
234567          204567

Result

CardID
123456
123450
123446
123456
156456
157456
121290
234567
124290
204567

Any help would be great here.

Thanks.

like image 368
happysmile Avatar asked Dec 28 '22 07:12

happysmile


1 Answers

SELECT ChildCard AS CardID FROM tbl UNION SELECT PrimaryCard FROM tbl

This should give you a list of distinct card entries, both child and primary.

like image 162
cairnz Avatar answered Dec 29 '22 20:12

cairnz