title: How to avoid null result of "SELECT max(rank) FROM test" for an empty table?
body: <p>I need to form an query in JPQL (2.0) to select a the max value (rank).</p>
  
  <p>I use: <code>SELECT max(rank) FROM test</code></p>
  
  <p>This works fine, except the case where the table is empty, then the result is <code>null</code>, but I need <code>0</code>.</p>
  
  <p><em>This would be no problem if I was able to "catch" the null with an simple if-statement, but I can't do this (the framework allows only to specify an JPA Query but no java code).</em></p>
  
  <p>Does anybody have an idea how to tune that query to get an <code>0</code> instead of an <code>null</code> if the table is empty? - The database is an MySQL, and native queries or stored procedures are no option. </p>