Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I keep getting this error: failed to INSERT: [1062] Duplicate entry 'Upping Your Type Game-' for key 'PRIMARY'.

The problem is, is that there are no duplicate entries. Which is why I'm confused when receiving that error.

Is there any way to check using InnoDB?

I have tried exporting the table and reading the SQL code and ran a search for any duplicates but there wasn't any.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It isn't saying that there is a duplicate entry in the table already, it is saying that there is already one entry in there with that value for the primary key and it is refusing to insert a second for that reason.

I suspect if you run SELECT * FORM <table> WHERE <keyfield>='Upping Your Type Game-', or if that key is a composite SELECT * FORM <table> WHERE <keyfield1>='Upping Your Type Game' AND <keyfield1>='', you will find one matching row, and that your code at the point of the error is trying to instert a second.

share|improve this answer
Aaaah! That makes sense and yes, it returns one matching row. Is there a way to get around this error? This is my INSERT code: $SQL = "INSERT INTO read(title,url) VALUES\n ".implode( "\n,",array_reverse( $sql_values ) ); – Chris Burton Jul 22 '13 at 19:20
Oh and there's an error in your SQL statement above. It should be FROM. – Chris Burton Jul 22 '13 at 19:22
Instead of grabbing all the articles from my feed, I wonder if I should just get the last article in the feed and let it INSERT or check the DB first and only INSERT what isn't there. Thoughts? – Chris Burton Jul 22 '13 at 19:25
If you try INSERT a duplicate values for a primary key (or a unique index) you will always get that error. There are a couple of ways around it: check before you insert and either do an update (if something might have changed) or just don't do anything. There is also the mysql specific "ON DUPLICATE KEY UPDATE" option (see…) if you are happy to sacrifice compatibility with other RDBMSs. – David Spillett Jul 23 '13 at 10:57
@ChrisBurton, If you want duplicates, remove that primary key duh... – Pacerier Feb 23 at 16:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.