Click here to Skip to main content
13,142,182 members (55,722 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.7K views
3 bookmarked
Posted 11 May 2010

SQL COUNT(*) Vs COUNT(column_name)

, 11 May 2010
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
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

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