Article View: borland.public.interbase.sql
Article #11256Re: Query problem
From: Fausto Brador
Date: Sun, 01 Dec 2002 04:35
Date: Sun, 01 Dec 2002 04:35
45 lines
2492 bytes
2492 bytes
Hi Donato!
Try
Insert Into table1
Select *
from table2 a
where not Exists(Select 1
From table1 b
Where b.cod = a.cod
And b.year = a.year
And b.subcod = a.subcod);
Bye
FBrador
"Donato Verrastro" <donato.verrastro@libero.it> wrote in message
news:3de74a9e@newsgroups.borland.com...
> I have a problem to write a query. Can you help me?
> I have a two table:
> CREATE TABLE1 (COD NUMBER(10,0),
> YEAR NUMBER(10,0),
> SUBCOD NUMBER(10,0),
> ..,
> PRIMARY KEY(COD,YEAR,SUBCOD));
> and table2
> CREATE TABLE2 (COD NUMBER(10,0),
> YEAR NUMBER(10,0),
> SUBCOD NUMBER(10,0),
> ..,
> PRIMARY KEY(COD,YEAR,SUBCOD));
> I want to insert in TABLE1 all record of TABLE2 that are not present in
> TABLE1.
> How can I do this query?
> I have write the following query but i think that it isn't correct.
> INSERT INTO TABLE1
> SELECT .... FROM TABLE2
> WHERE COD||'-'||YEAR||'-'||SUBCOD NOT IN (SELECT
> COD||'-'||YEAR||'-'||SUBCOD FROM TABLE2);
> Thank you in advance
> Donato Verrastro
>
>
>
>
Technical Details
Message-ID:
<3de991a9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3de74a9e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114a0e,793e98fa5f55bc1b X-Google-Attributes: gid114a0e,public X-Google-ArrivalTime: 2002-11-30 20:40:03 PST From: "Fausto Brador" <fbrador@hotmail.com> Newsgroups: borland.public.interbase.sql References: <3de74a9e@newsgroups.borland.com> Subject: Re: Query problem Date: Sun, 1 Dec 2002 00:35:59 -0400 Lines: 47 Organization: None X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 64.32.112.113 Message-ID: <3de991a9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1038717353 64.32.112.113 (30 Nov 2002 20:35:53 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail