another solution :)create table p(name char(10),n int)insert into pselect 'AA',10 union allselect 'AA',12 union allselect 'AA',4 union allselect 'BB',11 union allselect 'CC',51 union allselect 'CC',33select cast(name as varchar(20)) as r ,row_number() over(order by name asc) as RN ,1 as table_orderinto tempFrom punion allselect cast(n as varchar(20)) as r ,row_number() over(order by name asc) as RN ,2 as table_orderfrom porder by RN, table_orderselect r from temp