title: How to: Group items, retrieve one (random) row data of group and count rows in each group at one SQL clause
body: <p>I have simple table in database where are columns error_id, error_group_id and message. I want to show listing in UI which shows Message and occurrences of each error group.</p>
  
  <p>Error message may vary slightly (for eg: Settings X expired on date) where date may change for example, but error_group_id, which is hash from defined constants which want to be used for grouping, doesn't change (for eg, may be (AssemblyName+"Settings expired").GetHashCode().</p>
  
  <p>Currently I can list the groups with messages:</p>
  
  <pre><code> SELECT message, error_group_id
   FROM (SELECT error_id, message, error_group_id,
   rank() OVER ( PARTITION BY error_group_id ORDER BY error_id) rank
   FROM cc_errors)
   WHERE rank &lt;= 1;
  </code></pre>
  
  <p>Outputs:
  (just pick one random) message, group hash. (Only once per group).</p>
  
  <p>However, I want information about how many individual error messages is inside of group (double click group opens window which shows listing of individual errors). I'd like to count occurrences of each group in this SQL clause.</p>
  
  <p>So wanted output is following (single row per group):</p>
  
  <p>message, group hash, count of messages inside of group.</p>
  
  <p>Project is using oracle as database.</p>
  
  <p>Could someone help with this :P</p>