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 SQL Basics Finding the Data You Want Filtering by Dates

Thue Madsen
Thue Madsen
4,219 Points

"You didn't select all columns" but there are not more columns.

This is my query: SELECT id, home_team, home_score, away_team, away_score, played_on FROM results WHERE away_team = "Hessle" AND played_on >= "2015-10-01";

Why do I keep getting this error?

"Challenge Task 1 of 1 We're back in the sports team database. There's a results table with the columns id, home_team, home_score, away_team, away_score and played_on .

Find all the matches in the results table where "Hessle" was playing away as the away team and if they played on or after October 1st 2015. Date format is "YYYY-MM-DD".

Type in your command below, then press Ctrl-Enter."

Yes your SQL is correct and it should have passed

3 Answers

Did you use SELECT * to get all columns?

SELECT * FROM results WHERE away_team = "Hessle" and played_on >= "2015-10-01"
Thue Madsen
Thue Madsen
4,219 Points

Thanks, Kris! That worked.

However, I don't understand why. Although it is easier to use *, instead of listing all the columns it should yield the same results, right?

Thue Madsen You are correct in that you achieved the same results listing out the column names as you would by using the star notation. So, in real-life applications, you would be returning the exact same accurate set of information.

However, let's say that someone came along after you created this query and decided that they wanted to track some other info about the game's results as well -- perhaps to track the team's performance in rainy vs sunny weather, or morning vs afternoon games. If they then ran your query, they would no longer get all the data that was included in the table; they would have to revise the query. If, however, the original query was SELECT * FROM results, then the weather or time_of_day columns would be automatically included.

I assume this challenge is looking not just at whether all the info from the table ends up on the screen, but rather if you explicitly state that ALL data should be returned.

Two other benefits of using the * ......

  • (a) gives you all the columns even if you haven't been given a list of them like you were in this situation, and
  • (b) eliminates a lot of potential errors. id, home_team, home_score, away_team, away_score, played_on is 59 characters; * is 1 character. That means you have 58 more chances of a typo in your query than in Treehouse's expected answer.

As one who seems to live to make stupid typo errors and never be able to find them ..... I can tell you that you want to do as much as possible to eliminate those opportunities. ;-)