Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Limiting the output
Eliminating duplicate results
Aggregation
13. Count the rows, ignore the NULLS
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

Naturally, the asterisk (*) isn't the only option available in the function COUNT(). For example, we may ask the database to count the values in a specific column:

SELECT COUNT(customer_id)
FROM orders;

What's the difference between COUNT(*) and COUNT(customer_id)? Well, the first option counts all rows in the table and the second option counts all rows where the column customer_id has a specified value. In other words, if there is a NULL in the column customer_id, that row won't be counted.

Exercise

Check how many non-NULL values in the column position there are in the employees table. Name the column non_null_no.

Stuck? Here's a hint!

Type:

SELECT COUNT(position) AS non_null_no
FROM employees;