I am trying to prevent duplicate entries in a MySQL table. I've tried INSERT IGNORE but it doesn't seem to work. I believe that this is because I have an auto increment column and thusly no two rows will ever be duplicates.
So, I am trying to use WHERE NOT EXISTS like this
$sql = "INSERT INTO testresults (ttime, resno, course, vid, playdate) VALUES (:ttime, :resno, :course, :vid, :playdate)
WHERE NOT EXISTS (SELECT * FROM tempresults WHERE vid = :vid AND playdate = :playdate) LIMIT 1)";
but this returns
SQLSTATE[42000]: Syntax error or access violation: 1064
There are numerous examples on Stack Overflow but they all seem to want the inserted values to come come from a SELECT statement; whereas I am inserting from programmatically generated values.
I think I just need a little tweak to the SQL stateent.
Thanks!