Wednesday, January 28, 2015

Union of multiple CTE'S

Hello,


I have a piece of code which goes like this ---


A]


with cte1 AS (


), cte2 as (


),


select a,b,c


B]


with cte3 AS (


), cte4 as (


),


select x,y,z.


I need a way to union these 2 result sets. I can't write all 4 concurrently and then select as I would need to uniquely identify elements in each SET A and SET B. One approach i see is to put result set of each in a temp table and then finally do union all with temp tables. Would like suggestions or any other better way. As i have aboout 8 of such similar individual sets.


Thanks


No comments:

Post a Comment