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 trialLucian Dumitru
Courses Plus Student 13,024 PointsWhy the genre column did not update?
Hi, To update the missing genre raw, I tried my own statement and it did not worked, can you explain why? Here is the query:
UPDATE books SET genre="Classic" WHERE genre = NULL;
Thank you for your answer. Lucian
4 Answers
Steven Parker
231,269 PointsFYI: You can never compare anything to NULL
, or do any kind of calculation using NULL
.
All comparisons against NULL
are false, even when you reverse the sense of it, for example:
... WHERE genre = NULL /* this is always false */
... WHERE genre != NULL /* this is always false, too */
... WHERE 1 + NULL > 2 /* also false */
... WHERE 1 + NULL <= 2 /* still false */
As Justin suggested, only the identity comparisons (IS
and IS NOT
) work with NULL
.
Justin Horner
Treehouse Guest TeacherHello Lucian,
Try executing your statement again but instead of using = NULL
use IS NULL
like so:
UPDATE books SET genre="Classic" WHERE genre IS NULL;
I hope this helps.
Lucian Dumitru
Courses Plus Student 13,024 PointsThank you, It worked!
Justin Horner
Treehouse Guest TeacherYou're welcome!
A X
12,842 PointsHi Steven, I wanted some clarification, so IS NULL is what you'd check in a database... like IS the field loves_sushi NULL (no value)? In my case, if I was in a database, my loves_sushi field would have "yes" in it, so it would not be pulled in the query.
Whereas NULL is assigning that value to something. Like you could assign "my row" under the column of loves_swimming to NULL because I can't swim.