At 01:40 PM 20/10/2011, Ed Grochowski wrote:
>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?
>
>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) ?

INSERT INTO emp (fruits) values ('mango')
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

Reply via email to