Reputation: 59
I am working on a database project. I can successfully read an event XML feed from another website and place it into the database (via php).
internal_id
is controlled by me and needed externalinstance_id
is pulled from the feed and I want to insert it if it does not exist.
I am trying to achieve that the events have their own eventinstance_id
(I want to use this to insert only unique), and I have my own internal_id
. How do I "insert if external_id
is not in the database" (ignore duplicated)?
I have tried to use a select where not exists in phpmyadmin (trying to build the query), however, when I perform the query I get this SQL syntax error on phpmyadmin:
I want to insert if there isn't a internal_id
of 2 for example.
I'm using:
Upvotes: -1
Views: 258
Reputation: 702
Make eventinstance_id as Unique Id and use can use "INSERT IGNORE" QUERY. It will insert only unique values.
Example :- INSERT IGNORE INTO table (pid,uid,data) VALUES (1,34,56);
Where pid is primary key and uid is unique key.
Below you can find more details on Insert Ignore "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
Upvotes: 3