Q.Which aggregate function in SQL displays the number of values in the specified column ignoring the NULL values ? (A) len() (B) count() (C) number() (D) num()
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 →The COUNT() aggregate function in SQL is used to display the number of values in a specified column, inherently ignoring NULL values.
In SQL, aggregate functions are powerful tools designed to perform calculations on a set of rows and return a single summary value. These functions are fundamental for data analysis, allowing us to derive insights like sums, averages, maximums, minimums, and counts from large datasets. When dealing with real-world data, it's common to encounter NULL values, which represent missing or unknown data. How these NULL values are handled by aggregate functions is a crucial aspect of understanding their behavior.
The question specifically asks for an aggregate function that counts the number of values in a column while ignoring NULL entries. Among the standard SQL aggregate functions, COUNT() is precisely designed for this purpose.
Let's break down how COUNT() works:
-
COUNT(column_name): When you specify a column name inside theCOUNT()function, likeCOUNT(EmployeeID)orCOUNT(ProductName), SQL will iterate through each row in that column. For every row where the specifiedcolumn_namehas a non-NULL value, it increments the count. Rows where thecolumn_nameisNULLare simply skipped and do not contribute to the total count. This is the exact behavior requested by the question. -
COUNT(*): It's important to distinguishCOUNT(column_name)fromCOUNT(*). TheCOUNT(*)function counts the total number of rows in the result set, regardless of whether any specific column in those rows containsNULLvalues. It essentially counts the rows themselves, not the non-NULL values within a particular column.
COUNT(column_name) counts only non-NULL values in the specified column, whereas COUNT(*) counts all rows, irrespective of NULLs in any column.
Now, let's consider the other options provided: …
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.