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

Colton Wollin
Colton Wollin
738 Points

How can I find everything that isn't one of the numbers?

Review ratings should be only be 1-5. Find all the invalid ratings in one query. So far I have SELECT * FROM reviews WHERE ratings and then I'm not sure how to go from there.

Colton, I'm a tad confused by your original question. "Review ratings should be only 1-5" will be a different query than "Find all the invalid ratings in one query" query. Carlos addresses the invalid ratings query. My code addresses the "Review ratings should be only 1-5". So between Carlos and myself you can see that changing a simple word can change a lot with the outcome and the meaning of the query!

4 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

Then you do it like this:

SELECT *
FROM reviews
WHERE ratings NOT BETWEEN 1 AND 5;  

I hope that helps a little bit.

You use NOT BETWEEN.

Colton, I assume you're referring to a code challenge, but I have no idea which one as the ones after Filtering Out have to do with books not ratings. I think what you're asking about has to do with using BETWEEN:

SELECT *
FROM reviews
WHERE ratings BETWEEN 1 AND 5;  

So this query will return all fields from reviews where the rating of the review is between 1 and 5. You may want to review "Searching within a Range of Values": https://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/searching-within-a-range-of-values for more information.

If this isn't what you're looking for, I'm happy to help, but it might be good to re-phrase your question and point to a specific challenge...if that's the issue.

Colton Wollin
Colton Wollin
738 Points

I need the opposite of that. It's an sql playground challenge. It's basically I need every rating that is NOT 1 through 5

Bartlomiej Zabielski
PLUS
Bartlomiej Zabielski
Courses Plus Student 10,363 Points

yeah NOT BETWEEN i got confused and kept trying IS NOT BETWEEN derp derp