Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL to insert only new records
You can try something like this :
INSERT INTO table2
SELECT field1, field2, field3
FROM table1 a
WHERE NOT EXISTS (SELECT *
FROM table2
WHERE field1 = a.field1
AND field2 = a.field2)
Not necessary faster but clearer.
John Stathakis <jlstath_at_mail.icon.co.za> wrote in article
<336DC9E2.6948_at_mail.icon.co.za>...
> Hello everyone,
>
> Here is a SQL statement I wrote to insert records from one table into
> another. The catch is that it ignores records that are already there, so
> you never have a duplicate primary key failure.
>
> Does this statement bypass the indexes, causing performance problems ?
>
> INSERT INTO table2
> SELECT a.field1, a.field2, a.field3 FROM
> table1 a, table2 b
> WHERE
> b.field1(+) = a.field1 AND
> b.field2(+) = a.field2 AND
> b.field1 is null AND
> b.field2 is null;
>
> Regards,
> John
>
Received on Tue May 06 1997 - 00:00:00 CDT
![]() |
![]() |