Subject | Re: How to insert only if a matching row does not exist? |
---|---|
Author | gastrocus |
Post date | 2011-10-20T21:34:46Z |
--- In firebird-support@yahoogroups.com, "gastrocus" <gastrocus@...> wrote:
The above statement seems to do a separate insert for each row in table which does not match the test.
So, when I tested it on a table which had 100 rows (non matching the 'ZZZZZ' test), it inserted 100 new rows, each with a 'ZZZZ' name.
>Whoops, I spoke too soon as I had tested it on a table with 1 row first and it appeared to work.
>
>
> --- In firebird-support@yahoogroups.com, "Helen" <helebor@> wrote:
>
> >
> > Would you like to try this:
> >
> > merge into t1 tab2
> > using t1 tab1
> > on tab1.name = tab2.name and tab1.name = 'ZZZZZ'
> > when not matched then
> > insert (type, name, sysid, flag) values (1, 'ZZZZZ', 1, 0)
> >
>
> That works like a charm!
> Thanks Helen.
The above statement seems to do a separate insert for each row in table which does not match the test.
So, when I tested it on a table which had 100 rows (non matching the 'ZZZZZ' test), it inserted 100 new rows, each with a 'ZZZZ' name.