Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

SQL COUNT(*) Vs COUNT(column_name)

0.00/5 (No votes)
11 May 2010CPOL 6.3K  
Well, another major point is that the two variants serve different purposes by definition. -- Count rows where 'column_name' is NOT NULLSELECT COUNT(column_name) FROM Table_Name-- Count ALL rows in Table_Name SELECT COUNT(*) FROM Table_Name-- ... which you just as well can...
Well, another major point is that the two variants serve different purposes by definition.

SQL
-- Count rows where 'column_name' is NOT NULL
SELECT COUNT(column_name) FROM Table_Name

-- Count ALL rows in Table_Name 
SELECT COUNT(*) FROM Table_Name

-- ... which you just as well can exchange with a constant
SELECT COUNT(1) FROM Table_Name


In other words, it's not "which one is faster", it's "which one serves the purpose".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)