I used the following command to avoid duplicates in a table :
INSERT INTO mytable (num,name)
SELECT 2,'example' FROM mytable WHERE NOT EXISTS
(SELECT * FROM mytable WHERE num=2 AND name='example') LIMIT 1;
It is working but NOT if mytable
is empty.
mytable also contain a AUTO_INCREMENT
id.
CREATE TABLE mytable (
id int(11) NOT NULL auto_increment,
num int(11) NOT NULL,
name varchar(100) NOT NULL,
PRIMARY KEY (id)
);
Do you recommanded another method or a workaround ?