Click here to Skip to main content
16,021,209 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to count number of rows in a table for a particular ID.

Instead of writing SELECT COUNT(*) FROM TABLE shall i write SELECT COUNT(Name) FROM TABLE???

then tell me for better performance which is suitable??
Posted

Instead of writing
Select count(*) from table
It will count null values and values


Select count(name) from table
It will count only the values present in Name column.

Second one is the better performance.
 
Share this answer
 
Results can be vary according to the column values available in the relevant table.

COUNT(*) - retrieve the count of all the rows available in the table.
COUNT(Name) - retrieve only the count of non-null values available in the selected table.

Hope this will help you.
 
Share this answer
 
Basically, if you do a COUNT(*), it returns an entire row of data and then counts it as 1, then goes to the next row and counts that as 2, and so on.

A COUNT(Name) would "count" a "Name" for row 1, a "Name" for row 2, and so on.

Anything you put in the COUNT() function work the same.

However, if you use a column name as the parameter, COUNT will return a count of NON-NULL values of that column.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900