I need a query for adding a data record to a table. I would like to check in advance whether the record, which is to be inserted into the table, already exists. Here is my code (it works):
INSERT INTO table1(field1, field2)
SELECT 'value1', 'value2'
FROM table1
WHERE NOT EXISTS (SELECT *
FROM table1
WHERE field1 = 'value1'
AND field2 = 'value2')
GROUP BY 'value1', 'value2'
I believe that my code is not very effective. Perhaps there is a better statement in order to achieve the same result?