Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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;