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 SQL Basics Finding the Data You Want Filtering Out or Finding Missing Information

Michael Reta
Michael Reta
255 Points

How do I query to find all of the rows with missing data without individually typing out each column name?

Example: SELECT * FROM movies WHERE (any row) IS NULL

1 Answer

Anna Pichugina
Anna Pichugina
25,266 Points

I googled around a bit and couldn't find an easy fix for selecting all rows which have null values in any column. Here's the gist of most answers: https://stackoverflow.com/questions/9705369/is-there-a-quick-way-to-check-if-any-column-is-null

If you have a lot of columns and want to speed things up a bit you could select your column names for the table, copy paste them into an IDE and use its multi-cursor shortcuts to insert the repeating 'IS NULL OR ' using something like:

SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'some_table';