24 July 2019

Next SQL trick allows you perform conditional INSERT with your query.

For example, lets do insert if record not exists yet:

SQL:

INSERT INTO my_table (id, name)  
    SELECT 1, 'name' FROM dual  WHERE NOT EXISTS (SELECT 1 FROM my_table WHERE ID = 1);