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 trialAtul Varma
4,285 PointsNULL 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
231,272 PointsCount with a specific column name ignores null values. But count with "*" as the argument considers all values.
Ryan Hartigan
3,426 PointsHow do we count distinct values while also including NULL as a distinct value? Steven Parker
Steven Parker
231,272 PointsThere 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.
Atul Varma
4,285 PointsAtul Varma
4,285 PointsThank you for your response.
Atul Varma
4,285 PointsAtul Varma
4,285 PointsHello 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
231,272 PointsSteven Parker
231,272 PointsThere 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.