title: How does ORA-00935 trigger? Seeking insight on Oracle SQL's nested group function methodology
body: <p>I'm using SQL*Plus, or Oracle 11g express, if that's relevant.</p>
  
  <p>I came across something curious that I wish to learn more about regarding nested group functions, as I am new to SQL I found the irony of the error and its solution curious:</p>
  
  <p><strong>This does not work</strong></p>
  
  <pre><code>where
  t1.col1 =
      (select col1
      from t2
      having count(col2) = max(count(col2))
  group by col1
  ;
  </code></pre>
  
  <p>With the above, I receive:</p>
  
  <blockquote>
    <p>ORA-00935: Group Function is Nested too deeply</p>
  </blockquote>
  
  <p><strong>This does work</strong></p>
  
  <pre><code>where
  t1.col1 =
      (select col1
      from t2
      having count(col2) =
          (select max(count(col2)) from t2 
          group by col1)
      group by t2.col1)
  ;
  </code></pre>
  
  <p><strong>Given the above I have two questions:</strong></p>
  
  <p><strong>1)</strong> Exactly how/where does the compiler/application become confused?</p>
  
  <p><strong>2)</strong> If only for clarity's sake, am I right in assuming the deeper sub-query 'fires' first, and returns a value for the upper sub-query, ergo skipping the mess entirely?</p>