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

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Insert Question

Re: SQL Insert Question

From: terryg8 <trg_at_ibm.net>
Date: 1997/09/19
Message-ID: <34230AB3.4C1D@ibm.net>#1/1

Phil Cook wrote:
>
> This query does not filter out the records that already exist, and
> I get primary key constraint violated. I broke the query into two
> PL/SQL sections to get it to work. Thanks in advance....
>
> insert into table1
> select a.primary_key from table2 a where not exists
> ( select * from table1 b
> where a.primary_key = b.primary_key );

Is this the correct statement? Offhand this looks ok if you are truly dealing with a.primary_key and b.primary_key. Apologies if I just can't see it :)

If however a.primary_key isn't actually a primary_key I can see how it would fail.

In that case you could use something like Insert into table1
select min(a.field) from table2 ....

or
insert into table1
(select distinct field from table2
 minus
 select primary_key from table1)

etc Received on Fri Sep 19 1997 - 00:00:00 CDT

Original text of this message

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