Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Aggregate and Numeric Functions Counting Results

NULL VALUES

At 2:34- Andrew says that COUNT function considers only NON NULL VALUES.(with the last_name example) But At 4:25: Andrew says that COUNT ignores ALL NULL Values and considers all values..

Confused!!!!!

2 Answers

Steven Parker
Steven Parker
231,269 Points

Count with a specific column name ignores null values. But count with "*" as the argument considers all values.

Thank you for your response.

Hello Steven,

Could you recommend any book which I can follow to practice more or any link you can help me with ?

Thank you.

Steven Parker
Steven Parker
231,269 Points

There are some SQL exercises on W3 Resource and some tutorials that might be useful for reinforcement on SQL Zoo, including one on this particular topic Using Null.

How do we count distinct values while also including NULL as a distinct value? Steven Parker

Steven Parker
Steven Parker
231,269 Points

There are a few ways to do that, but my favorite is using COUNT(*) (which includes nulls) on a derived table of distinct values:

SELECT COUNT(*)  
FROM (SELECT DISTINCT <your_column> FROM <your_table>)

For future issues, always create a fresh question instead of asking one as an "answer". It will reach more students that way.