If you are fine with implementing a general mechanism to avoid duplicates on columns column_a/b/c, you can simply add a composite unique constraint on both columns, like
ALTER TABLE mytable
ADD CONSTRAINT constr_ID UNIQUE (column_a, column_b, column_c);
If anything operation happens on the table that would generate duplicates, MySQL will raise a constraint violation error. You can ignore the error with the ON DUPLICATE KEY UPDATE
option :
INSERT INTO mytable(column_a, column_b, column_c)
VALUES(value_a, value_b, value_c)
ON DUPLICATE KEY UPDATE column_a = column_a;
In this demo on DB Fiddle, we are inserting 3 records with 2 duplicates, and we end up with 2 records in the table, as expected.
On the other hand, if you want to restrict the check on duplicate to just one query, and/or if you want to avoid wasting autoincrement sequences on duplicate keys, then you can turn to an INSERT ... SELECT
statement, with a WHERE NOT EXISTS
condition that does the duplicate check :
INSERT INTO mytable(column_a, column_b, column_c)
SELECT src.*
FROM (SELECT value_a column_a, value_b column_b, value_c column_c) src
WHERE NOT EXISTS (
SELECT 1
FROM mytable
WHERE
column_a = src.column_a
AND column_b = src.column_b
AND column_c = src.column_c
);
If you attempt to insert a duplicate, the query will do nothing (and will not generate an error or warning).
Demo on DB Fiddle.