title: SQLPLUS (Oracle) - Get MAX COUNT of GROUPBY
body: <p>I need to identify which Month has the most entries. Ive used the TO_DATE function to format the date column to just the MONTH. Also, SELECT COUNT(*) in combination with the GROUP BY Clause I am able to return all records month and count attributes. </p>
  
  <p>However, I need to be able to only return one row that is the MAX of the COUNT. IVE atempted to do so by adding a HAVING clause but returns an error. I suspect I need a subquery in here somewhere but am unsure as to how to go about it. </p>
  
  <pre><code>SELECT TO_CHAR(P.DATEREGISTERED,'MONTH') MONTH, COUNT(*) COUNT
  FROM PET P
  GROUP BY TO_CHAR(P.DATEREGISTERED,'MONTH')
  HAVING COUNT = MAX(COUNT);
  </code></pre>
  
  <p>Another Attempt:</p>
  
  <pre><code>SELECT TO_CHAR(P.DATEREGISTERED,'MONTH') MONTH, COUNT(*) COUNT
  FROM PET P
  GROUP BY TO_CHAR(P.DATEREGISTERED,'MONTH')
  HAVING COUNT(*) = (SELECT MAX(TO_CHAR(P.DATEREGISTERED,'MONTH')) FROM PET P);
  </code></pre>