insert into OPT (email, campaign_id) values(\'mom@cox.net\',100)
where not exists( select * from OPT where (email =\"mom@cox.net\" and campaign_id =100)) ;
>
Another approach would be to leverage the INSERT ALL syntax from oracle,
INSERT ALL
INTO table1(email, campaign_id) VALUES (email, campaign_id)
WITH source_data AS
(SELECT 'mom@cox.net' email,100 campaign_id
FROM dual
UNION ALL
SELECT 'dad@cox.com' email,200 campaign_id
FROM dual)
SELECT email
,campaign_id
FROM source_data src
WHERE NOT EXISTS (SELECT 1
FROM table1 dest
WHERE src.email = dest.email
AND src.campaign_id = dest.campaign_id);
INSERT ALL also allow us to perform a conditional insert into multiple tables based on a sub query as source.
There are some really clean and nice examples are there to refer.