Okay.
So what we've seen so far allows us to specify what columns we want.
Name an age only or only ID, but it still gives us every single result in the table.
So if we have 10,000 users in our database, if we wanted to select one, we don't have a way of doing
that right now.
We only can select all of them, which really is not that useful.
And in fact, most of the time when you're selecting things, you're doing it deliberately and you're
trying to find particular pieces.
You're not just trying to check in on your table, make sure everything's okay.
You're usually trying to, let's say, sign someone in.
It's an application you're trying to verify, find someone by their username and check if their password
matches that they entered into your website or something like that where you're searching for specific
data.
And to do that, we need to use what's known as the where clause.
So it's another magic keyword where, and it allows us to get specific.
It allows us to say, I want all cats who are four years old or I want all cats who are tabbies.
And those are very simple examples.
But later on, throughout this course, we'll continue to expand your arsenal for select and for searching.
You'll be able to do things like I want all cats that are Tabby is between the age of one and two and
whose name starts with the letter B, let's say.
So we'll be able to get much more specific.
But for now we're focusing on the basics.
And as a side note, I want to show you that we will use where all the time.
So it's not just for searching or for selecting, but we'll need to use it when we're updating or deleting
things as well, because unless we're trying to update every single thing or delete every single thing,
usually we want to update something specific.
So we might say, I want to update the cats where their age is too, and I want to make their age three.
Versus I want to update every single cat to have an age of three.
We could be more targeted using where.
So we're going to start by seeing how we use it to select.
So here's an example select star from Cats where age is four.
So notice the syntax.
Here we have our same select star from cats that will give us all cats.
But then we have this where age equals four.
So what this will do is only select the data from the Cats table where the age column is equal to four.
And if we try that now, if we look at our data actually, you'll see we have two cats, Ringo and Egg,
who are both four years old.
So if we do a select star from Cats, you see what we get.
But now if we modify that with our where age equals four semicolon, we only get those two results.
So we still get cat ID, name, breed and age because we use star that tells us the columns.
But now we only have two results because we used where to get specific.
One note notice that when I refer to age here, that is the column age.
So there's no quotes around it, it's just age.
So we can do the same thing here.
But this time I'm using name to drill down or to get specific.
So select star from cat where name is equal to egg.
And notice I use quotes here because it's no longer an integer like ages.
Name is fa cha, it's text.
So we need those quotes so we can try that.
Now.
Select star from cats where name equals egg just like that.
And you notice we get egg cat id, name, breed and age.
One side note while I'm here, you may come across this at some point.
What do you think will happen if I fully capitalize egg?
It still works.
So it's important to note that by default this is case insensitive.
So I could do lowercase g, uppercase g and it still gives me the same data.
So we'll see ways around this later on.
Oftentimes it is useful, though, to not worry about case if you're dealing with things like an email
address where case doesn't actually matter.
So if a user types in their email with a capital letter at the beginning versus lowercase, it should
still be the same email in your database, but we'll talk about that later.
I just wanted to point out that it's a thing, case and sensitivity.
So that's all there is for now to the WHERE clause.
Now there is a lot more that we will be seeing and working with.
Like I mentioned at the beginning of this lesson, we will come back and use where all the time and
in fact we're going to continue to use it for updating and deleting.
Like I said, we need to specify what we want to delete and what we want to update.
But I just want to make it clear we're not done with where there's a lot of add on functionality that
we'll see in ensuing sections.
Perfect.