Subject | Re: [firebird-support] How to insert only if a matching row does not exist? |
---|---|
Author | Helen Borrie |
Post date | 2011-10-20T01:20:45Z |
At 01:40 PM 20/10/2011, Ed Grochowski wrote:
where not exists (select 1 from emp where fruits = 'mango')
Look up INSERT OR UPDATE and also MERGE in the Language Reference Update. One or both might do what you want, more efficiently than NOT EXISTS. Not enough info here to guess what you're really going to do with it.
./heLen
>Using SQL only (no stored procedures), how do I construct a statement to insert values into a database table, if and only if, a row containing a field with a specific value does not already exist?INSERT INTO emp (fruits) values ('mango')
>
>In Sql Server (and others), you can do things like the following:
>
>IFNOTEXISTS(SELECT1FROMemp WHEREfruits ='mango')
> INSERTINTOemp (fruits)VALUES('mango')
>
>What is the analogous way to achieve this in Firebird (2.5) ?
where not exists (select 1 from emp where fruits = 'mango')
Look up INSERT OR UPDATE and also MERGE in the Language Reference Update. One or both might do what you want, more efficiently than NOT EXISTS. Not enough info here to guess what you're really going to do with it.
./heLen