Best way to order records when using union/unioun all

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 773
1st way:-
select id,name,address,'id1' orderkey from test1
union all
select id,name,address,'id2' orderkey from test3
order by orderkey,address;


2nd way:-
select * from 
(select id,name,address,1'sortby' from test1
union all
select id,name,address,2'sortby' from test3) t
order by sortby,address;

Comments or Responses

Login to post response