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

Claire Uzenski
Claire Uzenski
1,026 Points

having trouble with SQL, this is what I have so far, SELECT 'Hessle' FROM away_team WHERE results = 2015-10-01

There other equations also

Claire Uzenski
Claire Uzenski
1,026 Points

Here's another one SELECT 7.99, 9.99, 11.99 FROM price WHERE products

4 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

The order and format of an SQL statement is important. I feel you need some work on understanding this. This is not a bad thing or slight towards you as it happens to all of us. What I mean, though, is we all need to build a foundation of understanding base concepts in any skill we learn.

The format of a typical SQL Statement is as follows:

SELECT
[column name(s) from a table separated by comma, when more than one column, and without surrounding quotes]
FROM
[table name]
WHERE
[column name] [logical operator] [comparative value]
-- logical operators, e.g (w/o quotes) '=', '!=', '<>', '<', '>'
-- comparitive value, e.g. a string, number, or date

A real world example could be similar to:

-- Get the users with a first name of 'Mary' and last name is NOT 'Jones'
SELECT
FirstName, LastName, UserName
FROM
table_Users
WHERE
FirstName = 'Mary'
AND
LastName != 'Jones' -- You could use `<>` here as it means the same as `!=`, which means not equal to
Steven Parker
Steven Parker
231,268 Points

For your SQL (formatted with syntax coloring):

SELECT 'Hessle' FROM away_team WHERE results = 2015-10-01

Here's some hints:

  • When they say "all matches" they mean to return all columns ("SELECT * ")
  • 'Hessle' is not an item to SELECT, but you'll use it in the WHERE clause
  • "away_team" is the column you will want to use in the WHERE clause to look for "Hessle" in
  • "results" is table name and will be used in the FROM clause
  • dates need to be enclosed in quotes

The second example has similar issues of WHERE criteria being placed in the SELECT clause.

Claire Uzenski
Claire Uzenski
1,026 Points

I've followed all of your instructions, but I'm afraid I'm still doing something wrong.

Steven Parker
Steven Parker
231,268 Points

Show the query you have at this point.

Sean T. Unwin
Sean T. Unwin
28,690 Points

Use the following to get started and replace the brackets with actual names based off the hints.

SELECT
* -- retrieve all columns in table
FROM
[Results Table]
WHERE
[Away Team Column] = 'Hessle'
AND
[Played On Column] >= '2015-10-01'