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

Databases

Donnie Driskell
Donnie Driskell
2,243 Points

Difficulty answering Challenge using BETWEEN keyword:

We're back in our sports team database with the results table. The columns are id, home_team, home_score, away_team, away_score and played_on.

There are 30 days in September. Find all the games played in the results table in September 2015.

Just finished watching video on BETWEEN keyword... I have tried several answers and unfortunately, I can't figure this one out. :-(

My problem is only with the syntax of the range of dates.

Thanks to anyone willing to help. Donnie

ps this is my answer (of course not the correct one)

SELECT * FROM results WHERE played_on BETWEEN September 1 2015 and September 30 2015; SQL Error: near "1": syntax error

Donnie Driskell
Donnie Driskell
2,243 Points

After reviewing the question, I don't think there is enough info as how can I get the dates min and max if I do not know what the tables values are. Just trying to get this one figured out. Thanks

Juan Gonzalez
Juan Gonzalez
12,960 Points

Hi, in theory your logic is rigth, but your syntax isn't, you can't use exactly "September 1 2015" or "September 30 2015" as they are not a valid syntax for a SQL date format, in this case you should use a valid format like "YYYY-MM-DD" (with quotes) so it can matches the values in the played_on column.

You can see a little more of this in a previous video https://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/filtering-by-dates

So you should end up with a query like this

SELECT * FROM results WHERE played_on BETWEEN "2015-09-01" AND "2015-09-30";

Hope this can help, cheers!

Donnie Driskell
Donnie Driskell
2,243 Points

Just as Juan Gonzalez wrote me, I finally figured out what was going on and Juan is correct. It was the date format I was using. I went back to the video and watched again and took a hint. I was taking the date literally. So, I re entered the syntax as SELECT * FROM results WHERE played_on BETWEEN "2015-09-01" AND "2015-09-30";