Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question