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 trialAndreas Frost Nordstrøm-Hansen
2,443 PointsNeed 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?
5 Answers
Tim Knight
28,888 PointsAndreas,
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
Yael Cohen
Courses Plus Student 929 PointsIs this the only way? Is there a shorter way?
Tim Knight
28,888 PointsYael, 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.
sulaiman abouabdah
5,314 PointsBut why including id as it might be NULL? After all, it is a primary key. It can't be NULL anyway
Luke Vaughan
15,258 PointsHello,
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.
sradms0
Treehouse Project ReviewerNice. I wouldn't say that this is the most 'accurate', however, but the quickest way to solve the problem.
Laszlo Fazekas
815 PointsThanks Luke! :)
Dan Alex
2,323 PointsThanks Luke!
Sean Flanagan
33,235 PointsThanks Luke; that's a huge help!
Andreas Frost Nordstrøm-Hansen
2,443 PointsAndreas Frost Nordstrøm-Hansen
2,443 PointsSELECT * 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? :)