Help Center/
GaussDB/
Developer Guide(Distributed_V2.0-8.x)/
FAQs/
What Is the Difference Between count(*) and count(column)?
Updated on 2025-05-29 GMT+08:00
What Is the Difference Between count(*) and count(column)?
Answer: The count() function is an aggregate function used to calculate the number of rows. The differences are as follows:
- count(*) collects statistics on the number of rows in all columns. Data whose value is NULL is not ignored during statistics collection.
- count(column) contains only the column name column. Data whose value is NULL is ignored during statistics collection.
-- Create a table and insert data into the table. gaussdb=# CREATE TABLE test(c1 int); gaussdb=# INSERT INTO test VALUES(1),(2),(3); gaussdb=# INSERT INTO test VALUES(NULL); --count(*) counts the number of rows and does not ignore the data whose value is NULL. gaussdb=# SELECT count(*) FROM test; count ------- 4 (1 row) --count(column) counts the number of rows and does not ignore the data whose value is NULL. gaussdb=# SELECT count(c1) from test; count ------- 3 (1 row) -- Delete. gaussdb=# DROP TABLE test;
Parent topic: FAQs
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot