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: Simple(I hope) SQL question

Re: Simple(I hope) SQL question

From: Michael Serbanescu <mserban_at_postoffice.worldnet.att.net>
Date: 1997/08/05
Message-ID: <33E6BCAC.41B1@postoffice.worldnet.att.net>#1/1

Have you tried creating a PRIMARY KEY or UNIQUE constraint on table1 (field 1) before inserting rows from table2 into table1 ?

Hope this helps.

Michael Serbanescu



Lee Johnson wrote:
>
> I have what I hope is a simple SQL question. I'm not an SQL expert, and I
> have inherited a piece of SQL code that I need to fix. The program is
> trying to populate a table with two fields from a second table. The catch is
> I want to make sure the first field is unique in the new table, even though
> there may have been multiple instances of it in the old table. The code
> looks like this:
>
> insert into table1
> (field1, field2)
> select field1, field2
> from table2
> where field3='s'
> and field1 not in (select field1 from table1);
>
> This obviously doesn't work, as field 1 is not added to table 1 until after
> this statement is executed, so I end up with a duplicate field problem. Does
> anyone know of a way to make this work? I'm pretty sure I could create a
> view and then execute off of that, but I was hoping for an easier solution.
>
> --
> Lee Johnson
> harley.johnson_at_s*net.net
> (to reply, move the * in my address)
  Received on Tue Aug 05 1997 - 00:00:00 CDT

Original text of this message

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