Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

SQL COUNT(*) Vs COUNT(column_name)

, 11 May 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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".

License

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

Share

About the Author

Dennis Ålund
Database Developer Oddbit
Indonesia Indonesia
Oddbit is an IT consultancy company that specialize in databases and software development with a focus on security. The company is located in Stockholm, Sweden and Jakarta, Indonesia.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 12 May 2010
Article Copyright 2010 by Dennis Ålund
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid