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)
![Jan Lundeen](https://secure.gravatar.com/avatar/41ab4717ce3951f93667c7b39d43298d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jan Lundeen
5,885 PointsSQL Stage 4: Practice Problems: Find all loans that are overdue - not sure if my query is right.
Hi,
In Reporting for SQL, I was working on the section "SQL Stage 4: Practice Problems". In particular, I was trying to find all loans that are overdue. Here's my query:
SELECT * FROM loans where returned_on BETWEEN DATE('NOW',"- 2 days") AND DATE('now',"+2 days") AND returned_on IS null;
However, I'm not sure that it's correct since I got "Query returned no results". I looked at the table and no books are overdue. I would think I'd get zero, but I'm not sure. Any ideas?
Thanks,
Jan
![Jan Lundeen](https://secure.gravatar.com/avatar/41ab4717ce3951f93667c7b39d43298d?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jan Lundeen
5,885 PointsHi Vittorio,
I'm not sure exactly what you did. I looked in the link to the forum, but I can't find any non-compliant code. Can you help me out with this?
Thanks,
Jan
2 Answers
![Unsubscribed User](https://secure.gravatar.com/avatar/10ed0384ef5350cf8dda00135631f04c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Unsubscribed User
16,600 PointsYour query can never return results because you're asking for records where returned_on
is between two dates and where return_on IS NULL
; you can't do both.
You probably meant for the dates to be the return_by
field, but you really only need that to be greater than NOW
.
SELECT * FROM loans WHERE return_by < DATE('now') AND returned_on IS null;
![Jan Lundeen](https://secure.gravatar.com/avatar/41ab4717ce3951f93667c7b39d43298d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jan Lundeen
5,885 PointsYour rignt Ian. Thanks!
Jan
Vittorio Somaschini
33,371 PointsVittorio Somaschini
33,371 PointsHello Jan.
I have edited your question to follow the guidelines for pasting the code on the forum: https://teamtreehouse.com/forum/posting-code-to-the-forum
;)