If it exists, update it; if not, create it

INSERT INTO yourtarget (col1, col2, col3, ... , coln)
SELECT yourvalues
FROM yoursource
WHERE NOT EXISTS (
SELECT 1 FROM yourtarget
WHERE col1 = yourval1 AND col2 = yourval2 AND ...
)

1 Like