title: Insert new SQL row only if there is same value from other table
body: <p>Currently I'm having,</p>
  
  <p>Table1:</p>
  
  <pre><code>ID  |   DEVICEID    |  STATUS  |
  --------------------------------
  1   |   SN001       |  ENROLL  |
  2   |   SN002       |  ENROLL  |
  </code></pre>
  
  <p>Table2:</p>
  
  <pre><code>ID  |   DEVICEID    |  STATUS  |
  --------------------------------
  1   |   SN001       |  ENROLL  |
  2   |   SN002       |  ENROLL  |
  3   |   SN003       |  ENROLL  |
  4   |   SN004       |  ENROLL  |
  </code></pre>
  
  <p>There is a form to fill up in order to insert new DEVICEID and STATUS in Table1 using AJAX POST to PHP. Before update the SQL, how do I create a condition where Table1 only <strong>can be updated if only there is <em>same</em></strong> DEVICEID filled up in form with DEVICEID in Table2 else it will return error and will not update the Table1.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>"SELECT deviceid
  FROM table1
  INNER JOIN table2 ON table1.deviceid=table2.deviceid
  INSERT INTO table1(deviceId,status)
  VALUES('$deviceid', '$status')
  WHERE deviceid = deviceid";                 &lt;--- Not sure what I'm doing here, trying to compare
  </code></pre>