So I want to insert a new row but after checking, it doesn't already exist.
My table is quite simple;
CREATE TABLE IF NOT EXISTS table
(
id INT NOT NULL AUTO_INCREMENT,
pl VARCHAR(255) NOT NULL,
num1 INT NOT NULL,
num2 INT NOT NULL,
num3 INT NOT NULL,
PRIMARY KEY (pl)
) ENGINE=InnoDB;
So I changed the values to something simple for convenience.
I tried doing INSERT INTO table(pl, num1, num2, num3) VALUES(val,0,0,0) ON DUPLICATE KEY UPDATE pl=pl;
but the above still enters the record cause of the auto increment field.
I also tried doing the same but instead of ON DUPLICATE
, INSERT IGNORE INTO
but I got the same result.
So is there any way to insert the row only if the primary key doesn't exist and if it does do nothing? (right now a new identical row gets created where the increment is +1