-1

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.

Screenshot

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:

Screenshot

I want to insert if there isn't a internal_id of 2 for example.

I'm using:

  • Win 7
  • Apache 2.4.18
  • PHP 7.0.6
  • PHP EXT mysqli
  • phpmyadmin 4.5.1
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
hockeyfreak863
  • 59
  • 3
  • 12

1 Answers1

3

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"

Community
  • 1
  • 1
Lavanya Pant
  • 702
  • 7
  • 23