'Get list from two columns

I want to create a SQL query which gives a list in an order based on the below sequence

X|Y|
----
D|C|
B|A|
C|B|

I want one list in sequence

Z
    
A
B
C
D

No Idea, from where to start



Solution 1:[1]

create table #data(X nvarchar(40), Y nvarchar(40) )

INSERT INTO #data
SELECT 'D', 'C' union
SELECT 'B', 'A' union
SELECT 'C', 'B'


SELECT X FROM #data
UNION
SELECT Y FROM #data
ORDER BY 1

enter image description here

Solution 2:[2]

select a.X as Z from table a
union
select b.Y as Z from table b
order by Z

Solution 3:[3]

use this

select  X  from (
select X from table 
union  
select y from table 
)main
order by X

Solution 4:[4]

Maybe something like this?

SELECT DISTINCT a
FROM (
  (SELECT X AS a FROM table1)
  UNION
  (SELECT y AS a FROM table1)
)
ORDER BY a;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gaurang Prajapati
Solution 2 jarlh
Solution 3
Solution 4 Veso Alex