0
0
SQLquery~5 mins

COUNT function behavior in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL COUNT(*) function do?
COUNT(*) counts all rows in a table, including rows with NULL values in any column.
Click to reveal answer
beginner
How does COUNT(column_name) differ from COUNT(*)?
COUNT(column_name) counts only rows where the specified column is NOT NULL, ignoring rows with NULL in that column.
Click to reveal answer
intermediate
What will COUNT(1) count in a SQL query?
COUNT(1) counts all rows just like COUNT(*), because 1 is a constant and not NULL, so it counts every row.
Click to reveal answer
beginner
If a column has NULL values, will COUNT(column) include those rows?
No, COUNT(column) excludes rows where the column value is NULL. Only non-NULL values are counted.
Click to reveal answer
intermediate
Can COUNT be used to count distinct values? How?
Yes, use COUNT(DISTINCT column_name) to count unique non-NULL values in that column.
Click to reveal answer
What does COUNT(*) return in a SQL query?
ANumber of NULL values in a column
BNumber of rows with non-NULL values in a specific column
CNumber of distinct values in a column
DNumber of all rows including those with NULLs
Which COUNT function counts only non-NULL values in a column?
ACOUNT(*)
BCOUNT(1)
CCOUNT(column_name)
DCOUNT(DISTINCT *)
What will COUNT(1) return compared to COUNT(*)?
ACounts only rows where column 1 is not NULL
BCounts all rows, same as COUNT(*)
CCounts distinct rows
DCounts only NULL rows
How to count unique non-NULL values in a column?
ACOUNT(DISTINCT column_name)
BCOUNT(column_name)
CCOUNT(*)
DCOUNT(NULL)
If a column has NULL values, what does COUNT(column) do with those rows?
AIgnores them
BCounts them
CCounts them as zero
DReturns an error
Explain how COUNT(*) and COUNT(column_name) behave differently when counting rows.
Think about whether NULL values are included or excluded.
You got /3 concepts.
    Describe how to count unique values in a column using COUNT.
    Focus on the DISTINCT keyword.
    You got /3 concepts.