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 SQL Basics Finding the Data You Want Review & Practice with SQL Playgrounds

Andreas Frost Nordstrøm-Hansen
Andreas Frost Nordstrøm-Hansen
2,443 Points

Need help on the SQL Playground. Movies with any missing data

Find all movies with any missing data

My answer:

SELECT * FROM movies WHERE id OR title OR year_released OR genre IS NULL

It also displays the movies with rows with no missing data

why is that?

Andreas Frost Nordstrøm-Hansen
Andreas Frost Nordstrøm-Hansen
2,443 Points

SELECT * FROM movies WHERE id IS NULL OR title IS NULL OR year_released IS NULL OR genre IS NULL

okay so i made it like this now, and that works.

but if anybody has a shorter version doing the same please post? :)

5 Answers

Tim Knight
Tim Knight
28,888 Points

Andreas,

You've got it. It can feel a little long and verbose, but for the most part that's all correct. What's I'll typically do is break up the line with the various conditions on their own line just so it's a little easier for me to read. Like this:

SELECT * FROM movies 
WHERE id IS NULL 
   OR title IS NULL 
   OR year_released IS NULL 
   OR genre IS NULL

Is this the only way? Is there a shorter way?

Tim Knight
Tim Knight
28,888 Points

Yael, there are potentially other options that might be shorter depending on the type of SQL you're using. The best I can say however though is this is the way to do it, there isn't a standard shortcut.

But why including id as it might be NULL? After all, it is a primary key. It can't be NULL anyway

Hello,

You would actually use

SELECT * from movies WHERE id IN (title, year_released, genre) IS NULL;

For the most accurate SQL query.

You do this because the IN acts as a multiple OR statement. You are saying SQL I would like to find the movies where the columns ID TITLE YEAR_RELEASED, and GENRE have one space with NO DATA. This "IN" will allow this to happen.

Nice. I wouldn't say that this is the most 'accurate', however, but the quickest way to solve the problem.

Sean Flanagan
Sean Flanagan
33,235 Points

Thanks Luke; that's a huge help!