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

Tyler McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tyler McDonald
Full Stack JavaScript Techdegree Graduate 16,700 Points

More efficient way to solve "Movies with Any Missing Data"?

The solution for the Movies with Any missing data question would become extremely long if there were many columns:

-- Find all movies with any missing data

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

Is there a better way to solve this instead of listing each column?

1 Answer

Steven Parker
Steven Parker
231,248 Points

Since a primary key cannot be NULL, you can simplify this a bit by not testing the ID column.

Otherwise, if the database has a programming extension you could use that to write a function that uses table metadata to identify and test the columns, but that's not standard SQL (and way beyond the scope of this course).