What will the following SQL query retrieve?
SELECT count(age) FROM student;
What will the following SQL query retrieve?
SELECT count(age) FROM student;
Solution
✅ Correct Option: 1
COUNT(column_name) counts only the rows where that column is not NULL. So count(age) returns the number of students whose age value is present, and rows with a NULL age are skipped.
Option 2: this is what COUNT(*) does, since it counts every row whether or not any column is NULL.
Option 3: counting unique values needs COUNT(DISTINCT age); plain COUNT(age) counts duplicates too.
Both COUNT(*) and COUNT(age) give the same result only when age has no NULLs.
Related questions:
2026: 24 May Shift 1