Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases Modifying Data with SQL Updating Data in a Database Updating Specific Rows

Lucian Dumitru
Lucian Dumitru
Courses Plus Student 13,024 Points

Why 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
Steven Parker
218,691 Points

FYI: 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
Justin Horner
Treehouse Guest Teacher

Hello 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.

Hi 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.