Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no difference.</p> <p>Reason:</p> <blockquote> <p><a href="http://msdn.microsoft.com/en-us/library/ms175997.aspx" rel="noreferrer">Books on-line</a> says "<code>COUNT ( { [ [ ALL | DISTINCT ] expression ] | * } )</code>"</p> </blockquote> <p>"1" is a non-null expression: so it's the same as <code>COUNT(*)</code>. The optimizer recognizes it for what it is: trivial.</p> <p>The same as <code>EXISTS (SELECT * ...</code> or <code>EXISTS (SELECT 1 ...</code></p> <p>Example:</p> <pre><code>SELECT COUNT(1) FROM dbo.tab800krows SELECT COUNT(1),FKID FROM dbo.tab800krows GROUP BY FKID SELECT COUNT(*) FROM dbo.tab800krows SELECT COUNT(*),FKID FROM dbo.tab800krows GROUP BY FKID </code></pre> <p>Same IO, same plan, the works</p> <p>Edit, Aug 2011</p> <p><a href="https://dba.stackexchange.com/questions/2511/what-is-the-difference-between-select-count-and-select-countany-non-null-col/2512#2512">Similar question on DBA.SE</a>.</p> <p>Edit, Dec 2011</p> <p><code>COUNT(*)</code> is mentioned specifically in <a href="http://msdn.microsoft.com/en-us/library/ms175997.aspx" rel="noreferrer">ANSI-92</a> (look for "<code>Scalar expressions 125</code>")</p> <blockquote> <p>Case:</p> <p>a) If COUNT(*) is specified, then the result is the cardinality of T.</p> </blockquote> <p>That is, the ANSI standard recognizes it as bleeding obvious what you mean. <code>COUNT(1)</code> has been optimized out by RDBMS vendors <em>because</em> of this superstition. Otherwise it would be evaluated as per ANSI</p> <blockquote> <p>b) Otherwise, let TX be the single-column table that is the result of applying the &lt;value expression&gt; to each row of T and eliminating null values. If one or more null values are eliminated, then a completion condition is raised: warning-</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload