Not sure this will completely meet your requirement. I was not clear on what if anything associates a given row in VCHR_LINE_STG to a row in VCHR_DIST_STG in addition to the VOUCHER_NUMBER. In any case, this should give you some data, even if it is not ordered exactly as you would like it. The ordering logic can be tweaked.with cte as(select 'VCHR_HDR_STG' as SourceTable, 0 as RN, *from dbo.VCHR_HDR_STG union allselect 'VCHR_LINE_STG' as SourceTable, ROW_NUMBER() over (partition by VOUCHER_NUMBER order by (select null)), *from dbo.VCHR_LINE_STGunion allselect 'VCHR_DIST_STG' as SourceTable, ROW_NUMBER() over (partition by VOUCHER_NUMBER order by (select null)), *from dbo.VCHR_DIST_STG) select *from cteorder by VOUCHER_NUMBER, case when SourceTable = 'VCHR_HDR_STG' then 0 else 1 end, RN