Combining four tables in SQL Server -


i have 4 tables table a, table b, table c , table d. schema of 4 tables identical. need union these 4 tables in following way:

  1. if record present in table a considered in output table.

  2. if record present in table b considered in output table if not present in table a.

  3. if record present in table c considered if not present in table a , table b.

  4. if record present in table d considered if not present in table a, table b, , table c.

note -

  1. every table has column identifies table every record (i don't know if of importance)

  2. records identified based on particular column - column x not unique within each table

you (only 2 cases shown should see how extend this)

with cte1  ( select 't1' source, x, y t1 union select 't2' source, x, y t2 ), cte2 ( select *,        rank() on (partition x                      order case source                                 when 't1' 1                                 when 't2' 2                               end) rn cte1 ) select x,y cte2 rn=1 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -