title: How can i create an SQL IF statement to check if fields need updating
body: <p>I've created an update procedure that will change the values of a record in a table if the matching record in another table changed, however, how i've got it set up is that even though there is like 12 fields that can be updated, the procedure will update every one of them even if only 1 field has been changed</p>
  
  <p>this is ofcause inefficient, it takes about 50 seconds for just 1 record, not good if there is like a few hundred, i thought up the psudocode for this easy enough</p>
  
  <pre><code>if olddata != newdata
  
      UPDATE!!!
  
  endif
  </code></pre>
  
  <p>thing is that i have little to no experience with if statements in SQL, if i could work with PHP then it would be easy by just running a SELECT with a WHERE clause much like the if statement above then checking the number of rows it returned (if 0 then there is no change) but the procedure has to be just SQL, the best i could come up with is this</p>
  
  <pre><code>IF(SELECT o.field FROM originaltbale AS o INNER JOIN updatetable AS u ON o.primarykey = u.primarykey WHERE o.field &lt;&gt; u.field) != 0
  
       UPDATE!!!
  
  ENDIF
  </code></pre>
  
  <p>but i doubt that'll work cause i'm sure SELECT won't return the number of rows, how can i create an if statement that'll work like this</p>