title: JPA/JPQL COUNT question
body: <p>I have the following JPQL query -</p>
  
  <pre><code>SELECT f.md5 
  FROM File f, Collection leafCollections, Collection instCollections 
  WHERE (f.status = com.foo.bar.FileStatus.Happy OR f.status = com.foo.bar.FileStatus.Sad) 
        AND f.collectionId = leafCollections.collectionId 
        AND leafCollections.instanceCollectionId = instCollections.collectionId 
  GROUP BY f.md5, instCollections.collectionId 
  </code></pre>
  
  <p>It basically returns the md5s for files which are organized in a hierarchy (tree) such that if the same MD5 appears in more then one leaf in a particular branch of the hierarchy it will be only shown once (thanks to the GROUP BY). </p>
  
  <p>This works fine. Let's say I get 100 rows back. Each row containing an md5 as a string.</p>
  
  <p>Now I want to get the <strong>COUNT</strong> of the rows returned. I thought I could simply do:</p>
  
  <pre><code>SELECT COUNT(f.md5) 
  FROM File f, Collection leafCollections, Collection instCollections 
  WHERE (f.status = com.foo.bar.FileStatus.Happy OR f.status = com.foo.bar.FileStatus.Sad) 
        AND f.collectionId = leafCollections.collectionId 
        AND leafCollections.instanceCollectionId = instCollections.collectionId 
  GROUP BY f.md5, instCollections.collectionId 
  </code></pre>
  
  <p>However this returns 100 rows, each one containing a long representing the number of times the md5 appeared in a branch. What I wanted was simply to get 1 row back with a long value of 100 being the total count of rows the original query returned. I feel like I am missing something obvious.</p>
  
  <p>Suggestions? </p>