help on combining two big tables

Database
Enthusiast

help on combining two big tables

Hi ,

I need your quick help on combining two big tables, each table has data in the range of Billion/Millions.

 

My Question:  I have two tables namely Table1 & Table2. Let us take the below sample data

 

Table1:

ID             Name             Sal

10            A                 1000

20            A                  2000

30            A                   3000

 

Table2:

 

ID             Name           Sal

10            B                  10000

20            B                   20000

40            B                  40000

 

I need to combine these two tables and load this data into final table.

If ID present is in both the tables then pick only Table1 ID value. basically we should load complete Table1 data into final table and when it comes to table2 , process only the ID's which are not present in table 1.

 

My output should look like:

 

ID           NAME     SAL

10            A                 1000

20            A                  2000

30            A                   3000

40            B                  40000

 

I wrote a query with UNION and NOT IN.  But it is performing badly as these tables have massive data.

 

Could someone please let me know the best way to form this sql.

Thanks In advance.

 

 

 

 

 

 

1 REPLY 1
Highlighted
Enthusiast

Re: help on combining two big tables

SEL Coalesce(T1.ID,T2.ID),Coalesce(T1.NAME,T2.NAME),Coalesce(T1.SALARY,T2.SALARY)
FROM TABLE1 T1
FULL OUTER JOIN TABLE2 T2
ON T1.ID = T2.ID