Databases SQL Basics Finding the Data You Want Filtering by Dates

Claire Uzenski
Claire Uzenski
369 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
369 Points

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

4 Answers

Sean T. Unwin
MOD
Sean T. Unwin
Treehouse Moderator 28,623 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
182,341 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
369 Points

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

Steven Parker
Steven Parker
182,341 Points

Show the query you have at this point.

Sean T. Unwin
MOD
Sean T. Unwin
Treehouse Moderator 28,623 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'