Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Fast merge

Fast merge

From: Yann Doussot <doussot_at_gifrance.com>
Date: 16 Jan 1999 17:54:12 GMT
Message-ID: <slrn7a1ki3.rdg.doussot@draco.gifrance.com>

        Hello,

        I'm running Oracle 8.0.5 standard edition (Linux) and need some advice on a query. Basically, I want to merge two tables:

Table A has two columns: an id (char(21), unique) and a value (int)

aaaa 4
aaab 1
aaac 9
...

Table B has the same structure

        Table A is big ( > 1 million rows ), table B is far smaller ( < 50.000 rows )

        I want to merge tables this way: if an id exists in both table A and B, sum the values and place the new result in table A, if an id exists only in table B, insert (id, value) in table A.

        My first idea was to create a temporary table with:

select id, sum(value) from
  (select * from a
   union all
   select * from b)
  group by id;

        Is there a better way to proceed ?

---
Yann Doussot <doussot_at_gifrance.com>
Grey Interactive - France - http://www.gifrance.com/ Cell: +33 6 12 71 70 03 Work: + 33 1 46 84 85 00 Received on Sat Jan 16 1999 - 11:54:12 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US