title: How can I use SUBSELECT with JOIN?
body: <p>I want to build an OpenSQL query to return only the max <code>stat</code> value for all <code>objnr</code>.<br>
  This works:</p>
  
  <pre class="lang-sql prettyprint-override"><code>    SELECT O~OBJNR
        FROM JCDS AS O
        WHERE O~OBJNR = 'Obj12345'
        AND STAT = ( SELECT MAX(STAT) 
                       FROM JCDS AS I 
                       WHERE I~OBJNR = O~OBJNR ).
  </code></pre>
  
  <p>However, if I try to use a join, and not provide <code>objnr</code> directly, I get an error message:</p>
  
  <pre class="lang-sql prettyprint-override"><code>    SELECT O~OBJNR, O~STAT
        FROM JCDS AS O
        INNER JOIN AFVC 
            ON AFVB~OBJNR = O~OBJNR
        WHERE "AUFPL" = 'Aufpl12345' 
        AND O~STAT = ( SELECT MAX(STAT) 
                         FROM JCDS AS I 
                         WHERE I~OBJNR = O~OBJNR ).
  </code></pre>
  
  <p>The error message is meaningless; "SQL error"</p>