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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Elaine Tran](https://secure.gravatar.com/avatar/99149b895698687cd5b61c997452c1bf?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Elaine Tran
809 PointsIs there a better way to solve "Find all the invalid ratings in one query." I did NOT IN (1,2,3,4,5).
-- Review ratings should be only be 1-5. Find all the invalid ratings in one query
SELECT * FROM reviews WHERE rating NOT IN (1, 2, 3,4,5);
It worked, but I'm wondering if there's a better way. Thanks in advance.
4 Answers
![Joel Bardsley](https://uploads.teamtreehouse.com/production/profile-photos/125124/micro_GfP2kypW_400x400.jpg)
Joel Bardsley
31,249 PointsYou could use the BETWEEN operator, which would make the query:
SELECT * FROM reviews WHERE rating NOT BETWEEN 1 AND 5;
![Diana Ci](https://uploads.teamtreehouse.com/production/profile-photos/7998522/micro_1.jpg)
Diana Ci
18,672 PointsSELECT * FROM reviews WHERE rating < 1 OR rating > 5;
![sradms0](https://uploads.teamtreehouse.com/production/profile-photos/4752982/micro_scott_adams_th_mod_profile_pic.jpg)
sradms0
Treehouse Project ReviewerSELECT * FROM reviews WHERE rating NOT BETWEEN 1 AND 5 OR rating IS NULL;
![Mohammed Safiulla D](https://secure.gravatar.com/avatar/d4164684d6ff033ec76235edd0a748c5?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Mohammed Safiulla D
17,042 PointsI guess it's always better to be explicit when coding however I tried for columns where information was NULL (for example the year_released in movies table; there are no reviews with null ratings). I found that NOT BETWEEN removes NULL values by default. The following 2 lines give the same result :
select * from movies where year_released not between 2000 and 2005;
select * from movies where year_released not between 2000 and 2005 or year_released is null;
Still, I would do what you did and always be explicit while coding :)
![Codeon Tech](https://secure.gravatar.com/avatar/3b2a8f2f758316a364f1afe97a5818e9?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Codeon Tech
1,150 PointsSELECT * FROM reviews WHERE rating IN (5);
Elaine Tran
809 PointsElaine Tran
809 PointsThank you Joel! :)