title: Selecting distinct counts from nested subqueries
body: <p>I am trying to get pagination working with a query that has a left join. This is causing my count to be the number of rows, not the number of products. To paraphrase my query</p>
  
  <pre><code>SELECT * FROM (
  SELECT 
    DENSE_RANK() OVER (order by tmp.prodId, tmp.prodYear) as rnum, 
    COUNT(*) OVER () AS totalRecords,
    tmp.* 
  FROM (
    SELECT
      product.*, widget.* 
    FROM A_PROD product
    LEFT JOIN A_WID widget
      ON product.prodId = widget.prodId
      AND product.prodYear = widget.prodYear
    ORDER BY product.prodId ASC ) tmp
  )
  WHERE rnum BETWEEN 1 and 10
  </code></pre>
  
  <p>This is resulting in</p>
  
  <pre><code>|rnum|totalRecords|prodId|prodYear|widgetId|
  | 1  |     3      | 13   |  2013  |  xyz   |
  | 1  |     3      | 13   |  2013  |  abc   |
  | 1  |     3      | 13   |  2013  |  mno   |
  </code></pre>
  
  <p>when what I am looking for is</p>
  
  <pre><code>|rnum|totalRecords|prodId|prodYear|widgetId|
  | 1  |     1      | 13   |  2013  |  xyz   |
  | 1  |     1      | 13   |  2013  |  abc   |
  | 1  |     1      | 13   |  2013  |  mno   |
  </code></pre>
  
  <p>That way the orm will treat them as the same product with different widgets, the pagination will treat it as only one row in the output and the 'Displaying X products out of Y' message will be correct.</p>
  
  <p>Is this doable?</p>