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 Modifying Data with SQL Updating Data in a Database Updating Specific Rows

Lucian Dumitru
PLUS
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
229,732 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
STAFF
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.