Subject [firebird-support] Re: How to insert only if a matching row does not exist?
Author Svein Erling Tysvær
>Just realized you can make it even easier:
>
> merge
> into emp
> using rdb$database
> on emp.fruits = 'mango'
> when not matched then insert (fruits) values ('mango')

An alternative (just an alternative available on all Firebird - and probably many InterBase - versions, the MERGE construct requires a not all-to-old Firebird version) would be:

INSERT INTO emp (fruits)
select 'mango' from rdb$database
where not exists (select *
from emp
where fruits = 'mango')

Set