title: Compare variables then set a variable (IF sql)
body: <p>Tryng and failing to discover the correct syntax for an IF or IIF within a SQL SELECT (MySQL)</p>
  
  <p>Compare 2 variables and if different then set another variable to a value</p>
  
  <pre><code>IF(assetID &lt;&gt; previousAssetID) set @ts = vardtmin
  </code></pre>
  
  <p>Do I need another specifier that sts something to 1 if the statement resolves true?</p>
  
  <p>The full SELECT is -</p>
  
  <pre><code>SELECT 
  assetID, 
  IF(assetdID &lt;&gt; previousAssetID) set @ts=vardtmin, 
  nodeid, 
  @changed := IF(nodeid &lt;&gt; previousLocationID, @changed + 1, @changed) AS changed, 
  IFNULL(TIMESTAMPDIFF(SECOND, previousTs, ts), 0) AS secDiff
  </code></pre>
  
  <p>Regards
  Active</p>