title: Simple SQL query to select a max
body: <p>I need a small help with a SQL query. </p>
  
  <p>I have two tables: <code>tbltrans</code> and <code>tbltrans_temp</code>. I want to select the maximum of tbltrans_temp <code>max(tbltrans_temp.transid)</code>. </p>
  
  <p>If <code>tbltrans_temp</code> is empty and it returns null, it should then take the max of <code>tbltrans.transid</code>. </p>
  
  <p>If both tables are empty, it should just return 0. </p>
  
  <p>I tried the following but didn't get the result expected.</p>
  
  <pre><code>select ifnull(ifnull(max(t1.transid), max(t2.transid)), 0)  
  from tbltrans_temp t1 
  left join tbltrans as t2
  </code></pre>