I am trying to use the insert ignore statement to put a name in a database. I do not want to create duplicates, however, the insert ignore statement I use keeps inserting!
The statement is:
INSERT IGNORE INTO firstname(name) VALUES ('Tommy')
My database shows this:
id | name
-------------
1 Tommy
2 Tommy
3 Tommy
A couple bits of information for people helping me. My id is my primary key and it is auto incremented.
My guess is that because the new id is created automatically it thinks its a new result! I am not sure how to solve this expcept with a bigger SQL query checking if the name Tommy exists first
Thanks
It’s because the column
namefromfirstnametable isnot unique. Try to adduniqueconstraint using this DDL statement,then try if it still add duplicate name. Hope it works now 🙂