COUNT(*) vs COUNT(column)

COUNT(*) counts every row; COUNT(column) skips rows where that column is NULL.

sql
SELECT COUNT(*), COUNT(return_date)
FROM rental;

When to use

The reading calls this a critical exam trap. Its example: COUNT(*), COUNT(return_date) and COUNT(DISTINCT customer_id) on rental give three different numbers. PS 04 Q2 also compares total rentals with distinct ones.

See Read 01.

Appears in

No references yet.