title: Assignment Table INSERT INTO prevent duplicates
body: <p>I'd like to create a statement for my PHP function where I have an <code>UserID</code> and an <code>InteressenID</code> and update my <code>userinteressen</code> table depending on what the user has checked. I don't want duplicates in that table.</p>
  
  <p>I have found the <a href="https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html" rel="nofollow noreferrer"><code>INSERT ... ON DUPLICATE KEY UPDATE</code></a> in documentation, however, that doesn't work since in the table doesn't have an <code>UNIQUE</code> row set.
  Due working with MySQL, I don't have the <code>MERGE</code> statement.
  Since I receive the <code>InteressenID</code> from my PHP function, there's no need for a <code>JOIN</code>. I tried <code>INSERT IGNORE</code> described <a href="http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html" rel="nofollow noreferrer">here</a>, but it returned Error #1064
  For deleting, I was thinking about first setting the <code>InteressenID</code> to 0 and delete them afterwards.</p>
  
  <p>The tables:</p>
  
  <p><strong>User</strong></p>
  
  <pre><code>ID | Name
  ---+--------
  1  | "Agathe"
  2  | "Bernd"
  3  | "Charlie"
  </code></pre>
  
  <p><strong>Interessen</strong></p>
  
  <pre><code>ID | Name
  ---+------------
  1  | "Cars"
  2  | "Sport"
  3  | "Languages"
  </code></pre>
  
  <p><strong>userinteressen</strong></p>
  
  <pre><code>User | Interessen
  -----+-----------
  1    | 2
  1    | 3
  2    | 2
  </code></pre>
  
  <p>My not working attempts:</p>
  
  <pre><code>INSERT INTO userinteressen VALUES('$id','$interesse')
  SELECT *
  WHERE userinteressen.User IS NULL AND userinteressen.Interesse IS NULL;
  
  INSERT IGNORE INTO `userinteressen`
  SET `User`= 1
  `Interesse`= 2;
  </code></pre>
  
  <p>More Informations:
  I'm using PDO.
  The userinteressen-table was created by using the interface of phpmyadmin, thus I had no real idea, what the DB looked like.</p>
  
  <p>I exported the database to get some insights. I'm new to databases and had mostly theory. Here are the statements created by the Engine:</p>
  
  <pre><code>--
  -- Indices for Tabelle `userinteressen`
  --
  ALTER TABLE `userinteressen`
    ADD KEY `User` (`User`,`Interesse`),
    ADD KEY `Interesse` (`Interesse`);
  
  --
  -- Constraints of table `userinteressen`
  --
  ALTER TABLE `userinteressen`
    ADD CONSTRAINT `userinteressen_ibfk_1` FOREIGN KEY (`User`) REFERENCES `user` (`UserID`),
    ADD CONSTRAINT `userinteressen_ibfk_2` FOREIGN KEY (`Interesse`) REFERENCES `interessen` (`InteressenID`);
  
  COMMIT;
  </code></pre>
  
  <p>Thanks!</p>