title: MySQL Procedure Insert only if not exists
body: <p>I'm using MySQL Stored Procedures and I want to insert some rows from a table's database to another table's database through a stored procedure. More specifically from database "new_schema", table "Routers" and field "mac_address" to database "data_warehouse2", table "dim_cpe" and field "mac_address".</p>
  
  <p>This is the code I used in the first insertion, that worked perfectly.</p>
  
  <pre><code>insert into data_warehouse2.dim_cpe (data_warehouse2.dim_cpe.mac_address, data_warehouse2.dim_cpe.ssid)
  (select new_schema.Routers.mac_address, new_schema.Routers.ssid from new_schema.Routers, data_warehouse2.dim_cpe);
  </code></pre>
  
  <p>Now I have more rows in the table "Routers" to be inserted into "dim_cpe" but, since there are rows already there, I want just to insert the new ones.</p>
  
  <p>As seen in other posts, I tried a where clause: </p>
  
  <pre><code>where new_schema.device_info.mac_address != data_warehouse2.dim_cpe.mac_address
  </code></pre>
  
  <p>and a:</p>
  
  <pre><code>on duplicate key update new_schema.Routers.mac_address = data_warehouse2.dim_cpe.mac_address"
  </code></pre>
  
  <p>Both didn't work. What's the best way to do this?</p>
  
  <p>Thanks in advance.</p>