My goal is to only execute a SQL Insert if the same value not exists.
this is my table1:
id(auto_increment)
version(string)
My Query looks like this:
INSERT IGNORE INTO table1 (version) VALUES ('12345');
The problem is that the ignore statement not work because every row is different because of the id column (auto_increment).
Anybody here have a Solution to avoid double saving the same values?
Solution:
INSERT INTO table1 (version)
SELECT * FROM (SELECT '12345') AS tmp
WHERE NOT EXISTS (
SELECT version FROM table1 WHERE version = '12345'
) LIMIT 1;