Monday 15 April 2013

sql - rewrite a union query -


I have two tables with the same structure, let's say that most records in TA and TB TA and TB are identical There are some records in TA and there are no TAs in TB. I just want to get all records of TA and TB without any mimicry:

  TA union select * to * TB   

This query gives me the result I want but the output is not as good as the answer As a form of production, there are more than half a million figures in both tables, is there an easy way to get all records from both tables? Both tables have an ID column that has unique value and can be attached to it

You Do not exist + UNION ALL :

  Choose from TA union * Choose * from TB where not present (* Select * from TA * where TA KEY_ID = TB.KEY_ID)   

This receives non-duplicate from all data and TB in TA .

No comments:

Post a Comment