Lakhan Baheti Lakhan Baheti - 5 months ago 7
SQL Question

Sorting two column in one column

Suppose i have a table - persons

id | First Name | Last Name
-----------------------------'
1 AA BB
2 EE DD
3 CC FF


Here , i want to display first name and last name in 1 column.

Such that output would be
----------------------
AA
BB
CC
DD
EE
FF

Can i also display it as
------------------
1 AA
1 BB
3 CC
2 DD
2 EE
3 FF


Using Mysql query ??

Answer

You are looking for union all:

select first_name as name from persons union all
select last_name from persons
order by name;
Comments