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

Ethan Martin
PLUS
Ethan Martin
Courses Plus Student 1,883 Points

Find all movies with any missing data

-- Find all movies with any missing data

SELECT title FROM movies WHERE * IS NULL;

Why doesn't this work? Can't I use the * to indicated any column is Null?

2 Answers

Unfortunately, you can't use * in this case.

Try something like this:

SELECT col1, col2, col3 FROM mytable
    WHERE col1 IS NULL AND
    WHERE col2 IS NULL AND
    WHERE col3 IS NULL;
Ethan Martin
Ethan Martin
Courses Plus Student 1,883 Points

That seems strange that you wouldn't be able to group columns that have a certain value.

It seems to repetitive for code. You should be at least able to say WHERE (col1, col2, col3) IS NULL;

What if you don't know how many columns a table has? what if there are too many columns to list? If you wanted to return any data with missing information, there is no way SQL would make you list every column in the table. There has be a cheat way of saying, hey find my all the rows in this table if any of its columns are empty.

Michael Pashkov
Michael Pashkov
22,024 Points

-- Find all movies with any missing data

-- SELECT <columns> FROM <table> WHERE <condition 1> AND <condition 2> ...;
-- SELECT <columns> FROM <table> WHERE <condition 1> OR <condition 2> ...;

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