sql_language thread: AW: RE: Insert Table1 Rows Into Table2 if Table1 R- ows Don't Exist In Table2
Hi Balazs.
I finally used a "Where Not Exists" SELECT with INNER JOIN, within
another
SELECT, which did the trick.
Thanks.
Rita
-----Original Message-----
From: Petenyi, Balazs [mailto:BPetenyi@s...]
Sent: Thursday, November 15, 2001 1:24 AM
To: sql language
Subject: [sql_language] AW: RE: Insert Table1 Rows Into Table2 if
Table1
R ows Don't Exist In Table2
Hi Rita,
i think you have to use the script with OUTER JOIN. Because with Inner
Join
can never happen, that Table1.Field(x) is null.
Balazs
bpetenyi@s...
INSERT INTO Table2
> SELECT Table1.Field1,
> Table1.Field2,
> Table1.Field3,
> FROM Table1 RIGHT OUTER JOIN Table2 ON
> (Table2.Field1 =3D Table1.Field1 AND
> Table2.Field2 =3D Table1.Field2 AND
> Table2.Field3 =3D Table1.Field3)
> WHERE Table1.Field1 =3D null AND
> Table1.Field2 =3D null AND
> Table1.Field3 =3D null
-----Urspr=FCngliche Nachricht-----
Von: Rita Greenberg [mailto:rg1@h...]
Gesendet am: Mittwoch, 03. Oktober 2001 16:02
An: sql language
Betreff: [sql_language] RE: Insert Table1 Rows Into Table2 if Table1 R
ows Don't Exist In Table2
Thanks Luis. This way seems more efficient than mine with 2 selects.
-----Original Message-----
From: Luis Alvarez [mailto:luis_alvarez@y...]
Sent: Tuesday, October 02, 2001 2:34 PM
To: sql language
Subject: [sql_language] RE: Insert Table1 Rows Into Table2 if Table1
Rows Don't Exist In Table2
Rita:
Sorry, I believe is then in this way:
INSERT INTO Table2
> SELECT Table1.Field1,
> Table1.Field2,
> Table1.Field3,
> FROM Table1 INNER JOIN Table2 ON
> (Table2.Field1 =3D Table1.Field1 AND
> Table2.Field2 =3D Table1.Field2 AND
> Table2.Field3 =3D Table1.Field3)
> WHERE Table1.Field1 =3D null AND
> Table1.Field2 =3D null AND
> Table1.Field3 =3D null
If it doesn't work try left join instead of inner.
I don't have the book with me but I am sure that it
works in this way.
--- Rita Greenberg <rg1@h...> wrote:
> Hi Luis.
>
> Thanks for your response. I tried that but nothing
> was inserted.
>
> Somebody mentioned using "NOT EXISTS" and the
> following code worked for me:
> INSERT INTO Table2
> SELECT Table1.Field1,
> Table1.Field2
> Table1.Field3
> FROM Table1
> WHERE NOT EXISTS
> (SELECT Field1, Field2, Field3 FROM Table1 INNER
> JOIN
> Table2 ON
> Table2.Field1 =3D Table1.Field1 AND
> Table2.Field2 =3D Table1.Field2 AND
> Table2.Field3 =3D Table1.Field3)
> Rita
>
> -----Original Message-----
> From: Luis Alvarez [mailto:luis_alvarez@y...]
> Sent: Tuesday, October 02, 2001 12:08 PM
> To: sql language
> Subject: [sql_language] Re: Insert Table1 Rows Into
> Table2 if Table1
> Rows Don't Exist In Table2
>
>
> I had this problem once and believe it was solved
> like
> this. See the changes in the code.
>
> --- rg1@h... wrote:
> > Hi.
> >
> > I have Table1 rows I want to insert into Table2
> but
> > only those rows from
> > Table1 that don't already exist in Table2.
> >
> > I tried the following code but nothing got
> inserted
> > from Table1 into
> > Table2:
> > INSERT INTO Table2
> > SELECT Table1.Field1,
> > Table1.Field2,
> > Table1.Field3,
> > FROM Table1 INNER JOIN Table2 ON
> > (Table2.Field1 =3D Table1.Field1 AND
> > Table2.Field2 =3D Table1.Field2 AND
> > Table2.Field3 =3D Table1.Field3)
> > WHERE Table2.Field1 =3D null AND
> > Table2.Field2 =3D null AND
> > Table2.Field3 =3D null
> > I'm using SQL 7.0.
> >
> > Any help would be greatly appreciated!
> >
> > Rita
> >
> >
$subst('Email.Unsub')
$subst('Email.Unsub')
$subst('Email.Unsub')