Skip to content
Question 33 of 40

Q.Differentiate between COUNT ( ) and COURT (*) functions in MYSQL. Give suitable examples to support your answer.

Punjab PsebCBSE Class XII Board 2023Subjective· 2mImportance★★★★★
83% · 33/40 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

COUNT() is an aggregate function that counts rows or non-NULL values in SQL; COURT(*) does not exist in MySQL — the question likely confuses COUNT(*) (count all rows) with COUNT(column) (count non-NULL values in a column).

There appears to be a typo in the question. MySQL has no function called COURT(*). The standard aggregate function is COUNT(), which comes in two main forms: COUNT(*) and COUNT(column_name). Understanding the difference between these two is essential for writing correct queries.

The Concept: What COUNT() Does

COUNT() is an aggregate function that returns the number of rows that match a criterion. The key distinction lies in what you ask it to count:

  • COUNT(*) counts every row in the result set, regardless of NULL values.
  • COUNT(column_name) counts only rows where that specific column is NOT NULL.

This difference becomes critical when your table contains NULL values, which represent missing or unknown data.


The Two Forms of COUNT()

1. COUNT(*) — Count All Rows

COUNT(*) counts every row returned by the query, including rows where some or all columns are NULL.

Example:

Suppose we have a table students:

idnameemail
1Arjunarjun@example.com
2PriyaNULL
3Rohanrohan@example.com
4SnehaNULL
SELECT COUNT(*) FROM students;

Result: 4

All four rows are counted, even though two have NULL emails.


2. COUNT(column_name) — Count Non-NULL Values

COUNT(column_name) counts only the rows where the specified column contains a non-NULL value.

Example (same table):

SELECT COUNT(email) FROM students;

Result: 2

Only Arjun and Rohan have email addresses; Priya and Sneha's NULL emails are excluded.


Side-by-Side Comparison

FunctionWhat It CountsTreats NULL as
COUNT(*)All rows in the result setCounted
COUNT(column_name)Rows where column_name IS NOT NULLIgnored

Practical Use Cases

When to use COUNT(*): …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.