Reviewed by Aditya Kumar · Last reviewed 2026-08-08
Group by the column and count. That gives one row per distinct value with its frequency. The COUNT variants differ, and the difference is the interview question COUNT( ) counts rows, including rows…
This easy-level SQL question appears frequently in data engineering interviews at companies like Globant. While less common, it tests deeper understanding that distinguishes strong candidates. Mastering the underlying concepts (sql) will help you answer variations of this question confidently.
Start by clearly defining the core concept being asked about. Interviewers want to see that you understand the fundamentals before diving into implementation details. Structure your answer with a definition, then explain the practical application with a concise example. The expert answer includes a code example that demonstrates the implementation pattern.
Group by the column and count. That gives one row per distinct value with its frequency.
SELECT status, COUNT(*) AS occurrences
FROM orders
GROUP BY status
ORDER BY occurrences DESC;
COUNT(*) counts rows, including rows where every column is NULL.COUNT(column) counts rows where that column is not NULL. This is the one people get wrong.COUNT(DISTINCT column) counts distinct non-NULL values.So on a column with 100 rows of which 10 are NULL, COUNT(*) returns 100 and COUNT(status) returns 90. Subtracting the two is the idiomatic way to count NULLs:
SELECT COUNT(*) - COUNT(status) AS null_count FROM orders;
Note also that GROUP BY treats all NULLs as a single group, even though NULL does not equal NULL in a comparison — a deliberate exception in the standard.
SELECT COUNT(*) FROM orders WHERE status = 'shipped';
Rather than running separate queries, count conditionally. Because COUNT ignores NULLs, a CASE with no ELSE acts as a filter:
SELECT COUNT(CASE WHEN status = 'shipped' THEN 1 END) AS shipped,
COUNT(CASE WHEN status = 'cancelled' THEN 1 END) AS cancelled
FROM orders;
PostgreSQL and SQLite support the cleaner COUNT(*) FILTER (WHERE status = 'shipped'). SUM(CASE WHEN ... THEN 1 ELSE 0 END) works everywhere and is equivalent.
An index on the grouped column lets the engine use an index scan and, in some engines, skip the sort. COUNT(DISTINCT ...) is markedly more expensive than COUNT(*) because it must deduplicate; at large scale, approximate functions such as APPROX_COUNT_DISTINCT or HyperLogLog trade a small error for a large speedup.
In the interview, also mention that COUNT(1) and COUNT(*) are identical in every major engine — the supposed performance difference is a myth.
Red Flag: COUNT(*) when you need non-null count—different semantics. Pro-Move: 'We used COUNT(CASE WHEN status='active' THEN 1 END) for conditional count in single pass.'
Some links below are affiliate links. If you buy through them we may earn a small commission at no extra cost to you — it helps keep DataEngPrep free.
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.