title: SQL Server: How can I use the COUNT clause without GROUPing?
body: <p>I'm looking get two things from a query, given a set of contraints:</p>
  
  <ul>
  <li>The first match</li>
  <li>The total number of matches</li>
  </ul>
  
  <p>I can get the first match by:</p>
  
  <pre><code>SELECT TOP 1
      ID,
      ReportYear,
      Name,
      SignDate,
       ... 
  FROM Table
  WHERE
       ...
  ORDER BY ... //I can put in here which one I want to take
  </code></pre>
  
  <p>And then I can get the match count if I use</p>
  
  <pre><code>SELECT
      MIN(ID),
      MIN(ReportYear),
      MIN(Name),
      MIN(SignDate),
       ... ,
      COUNT(*) as MatchCount
  FROM Table
  WHERE
       ...
  GROUP BY
       ??? // I don't really want any grouping
  </code></pre>
  
  <p>I really want to avoid both grouping and using an aggregate function on all my results. This question <a href="https://stackoverflow.com/questions/3368967/sql-server-select-count-without-using-aggregate-function-or-group-by">SQL Server Select COUNT without using aggregate function or group by</a> suggests the answer would be</p>
  
  <pre><code>SELECT TOP 1
      ID,
      ReportYear,
      Name,
      SignDate,
       ... ,
      @@ROWCOUNT as MatchCount
  FROM Table
  </code></pre>
  
  <p>This works without the TOP 1, but when it's in there, @@ROWCOUNT = number of rows returned, which is 1. How can I get essentially the output of COUNT(*) (whatever's left after the where clause) without any grouping or need to aggregate all the columns?</p>
  
  <p>What I don't want to do is repeat each of these twice, once for the first row and then again for the @@ROWCOUNT. I'm not finding a way I can properly use GROUP BY, because I strictly want the number of items that match my criteria, and I want columns that if I GROUPed them would throw this number off - unless I'm misunderstanding GROUP BY.</p>