65.9K
CodeProject is changing. Read more.
Home

SQL COUNT(*) Vs COUNT(column_name)

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

May 12, 2010

CPOL
viewsIcon

6280

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.
-- 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".