title: MySQL INSERT INTO WHERE NOT EXIST
body: <p>I will like to insert into same table if the ip_address for the product_id wasn't exist but preferably not to create two separate query. How can I achieve it?</p>
  
  <p>Below will be the sample table:</p>
  
  <pre><code>id | product_id | ip_address |
  ------------------------------
  a    11112        8.8.8.8
  b    11234        9.9.9.9
  </code></pre>
  
  <p>and my code is something like this but it doesn't work.</p>
  
  <pre><code>INSERT INTO `'._DB_PREFIX_.'views` 
  (SELECT '.$id_product.',"'.$ip_addr.'"
  FROM `'._DB_PREFIX_.'views` 
  WHERE NOT EXISTS (SELECT * FROM
  `'._DB_PREFIX_.'views` v WHERE v.id_product ='.$id_product.' AND
  t.ip_address ="'.$ip_addr.'"
  ))'
  </code></pre>