"HTML" was retired on January 6, 2020. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed SQL Reporting by Example!
You have completed SQL Reporting by Example!
Preview
Generate a list of students with last names from A to M.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Awesome, and one more thing.
0:00
The printer ran out of ink when
printing sign-in sheets for
0:02
the first half of our students.
0:05
If you could get a list of students
with last names from A to M,
0:06
that would be really helpful.
0:10
For this query, let's start by
selecting a list of all the students.
0:13
SELECT* FROM STUDENTS.
0:17
Then, lets add a WHERE clause.
0:19
And in this WHERE clause,
0:21
we need to limit our students to only
the ones with last names from A to M.
0:22
But before we do that,
I'm gonna real quick add the ORDER BY and
0:27
we want to do it by LAST_NAME ASCENDING.
0:31
Okay, getting back to the WHERE clause,
if you google for
0:34
this answer,
one thing you might come across is this.
0:36
So using the LIKE keyword we
can do something like this.
0:40
A to M, and then the % sign,
and what these brackets mean,
0:43
is that the first character in the last
name needs to be between A to M.
0:48
And then the % sign again which know
means, whatever comes after this is fine.
0:54
So this is saying, the first character
needs to be between A to M, and
0:59
all the remaining characters
we don't care about.
1:02
However, if we try to run this,
It doesn't work.
1:05
And that's because the syntax
doesn't work with SQLite.
1:09
It works with most SQL implementations,
it just doesn't work with this one.
1:13
So we'll have to take
a different approach.
1:17
So, what we are going to do, is instead of
using the LIKE keyword, we're just going
1:20
to see if the last name is after, or equal
to, the letter A, and before the letter N.
1:24
And to do that, we can chose
greater than and equal to signs.
1:31
So, let's do LAST_NAME, and
let's make sure it comes after or
1:35
is equal to the letter A, and
let's make sure, so AND LAST_NAME.
1:41
We wanna make sure its
less than the letter N.
1:47
And if we run this, there we go.
1:50
Last names with A.
1:53
If we scroll all the way
down to the bottom,
1:54
we get this very last one with Murray.
1:57
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up