WEBVTT

00:00.240 --> 00:07.680
OK so what we've seen so far allows us to specify what columns we want name and age only or only easy

00:08.100 --> 00:11.490
but it still gives us every single result in the table.

00:11.760 --> 00:17.910
So if we have 10000 users in our database if we wanted to select one we don't have a way of doing that

00:17.910 --> 00:18.600
right now.

00:18.750 --> 00:22.550
We only can select all of them which really is not that useful.

00:22.570 --> 00:27.210
In fact most of the time when you're selecting things you're doing it deliberately and you're trying

00:27.210 --> 00:28.700
to find particular pieces.

00:28.740 --> 00:32.020
You're not just trying to check in on your table make sure everything's OK.

00:32.070 --> 00:38.610
You're usually trying to let's say sign someone in if it's an application you're trying to verify find

00:38.610 --> 00:44.520
someone by their user name and check if their password matches that they entered into your website or

00:44.520 --> 00:47.380
something like that where you're searching for specific data.

00:47.700 --> 00:51.710
And to do that we need to use what's known as the WHERE clause.

00:51.930 --> 00:56.310
So it's another magic keyword where it allows us to get specific.

00:56.310 --> 01:04.500
It allows us to say I want all cats who are 4 years old or I want all cats who are Tabby's and those

01:04.500 --> 01:05.760
are very simple examples.

01:06.060 --> 01:12.130
But later on throughout this course we'll continue to expand your arsenal for select and for searching.

01:12.240 --> 01:19.350
You'll be able to do things like I want all cats that are Tabby's between the age of 1 and 2 and whose

01:19.350 --> 01:21.510
name starts with the letter B.

01:21.530 --> 01:22.280
Let's say.

01:22.380 --> 01:24.140
So we'll be able to get much more specific.

01:24.150 --> 01:27.090
But for now we're focusing on the basics.

01:27.240 --> 01:31.720
And as a side note I want to show you that we will use where all the time.

01:31.720 --> 01:37.200
So it's not just for searching or for selecting But we'll need to use it when we're updating or deleting

01:37.200 --> 01:42.370
things as well because we're trying to update every single thing or delete every single thing.

01:42.510 --> 01:50.370
Usually we want to update something specific so we might say I want to update the cats where their age

01:50.370 --> 01:57.290
is too and I want to make their age three versus I want to update every single cat to have an age of

01:57.290 --> 01:57.830
three.

01:57.950 --> 02:00.070
We could be more targeted using WHERE.

02:00.470 --> 02:03.930
So we're going to start by seeing how we use it to select.

02:04.170 --> 02:05.660
So here's an example.

02:05.660 --> 02:12.260
Select the star from cats where age is for so notice the syntax here.

02:12.430 --> 02:18.880
We have our same select star from CAS that will give us all cats but then we have this where age equals

02:18.880 --> 02:20.290
four.

02:20.290 --> 02:28.550
So what this will do is only select the data from the cat's table where the age column is equal to four.

02:29.170 --> 02:38.650
And if we try that now if we look at our data actually you'll see we have two cats Ringo and egg who

02:38.650 --> 02:41.080
are both four years old.

02:41.080 --> 02:43.950
So if we do a select start from cats you see what we get.

02:44.140 --> 02:53.480
But now if we modify that with our where age equals four semi-colon we only get those two results.

02:53.500 --> 02:59.600
So we still get cat ID name breed and age because we you start that tells us the columns.

02:59.800 --> 03:04.590
But now we only have two results because we used where to get specific.

03:04.660 --> 03:09.680
One note noticed that when I refer to age here that is the column age.

03:09.710 --> 03:11.170
There's no quotes around it.

03:11.290 --> 03:13.690
It's just age.

03:13.690 --> 03:20.560
So we can do the same thing here but this time I'm using name to drill down or to get specific.

03:20.560 --> 03:22.160
So select star from cat.

03:22.240 --> 03:24.350
Name is equal to egg.

03:24.520 --> 03:29.520
And notice I use quotes here because it's no longer an integer like ages.

03:29.980 --> 03:31.230
Name is far char.

03:31.450 --> 03:32.200
It's text.

03:32.200 --> 03:34.740
So we need those quotes so we can try that.

03:34.740 --> 03:42.680
Now select star from cats where name equals egg.

03:42.820 --> 03:50.130
Just like that you notice we get egg cat ID name breed and age.

03:50.170 --> 03:55.290
One side note while I'm here you may come across as at some point.

03:55.390 --> 03:58.410
What do you think will happen if I fully capitalize eg.

04:01.140 --> 04:02.790
It still works.

04:02.790 --> 04:07.290
So it's important to note that by default this is case insensitive.

04:07.380 --> 04:14.040
So I could do lowercase g uppercase G and it still gives me the same data.

04:14.430 --> 04:16.480
So we'll see ways around this later on.

04:16.500 --> 04:22.710
Oftentimes it is useful though to not worry about case if you're dealing with things like an email address

04:23.220 --> 04:24.840
where case doesn't actually matter.

04:25.020 --> 04:30.540
So if a user types in their email with a capital letter at the beginning versus lower case it should

04:30.540 --> 04:32.650
still be the same email in your database.

04:32.790 --> 04:33.990
But we'll talk about that later.

04:33.990 --> 04:40.410
I just wanted to point out that the thing case insensitivity So that's all there is for now to the where

04:40.410 --> 04:40.910
clause.

04:40.980 --> 04:44.790
Now there is a lot more that we will be seeing and working with like I mentioned at the beginning of

04:44.790 --> 04:48.540
this lesson we will come back and use where all the time.

04:48.540 --> 04:52.210
And in fact we're going to continue to use it for updating and deleting.

04:52.230 --> 04:56.860
Like I said we need to specify what we want to delete and what we want to update.

04:57.270 --> 05:01.680
But I just want to make it clear we're not done with where there's a lot of add on functionality that

05:01.680 --> 05:04.140
we'll see in ensuing sections.

05:04.140 --> 05:04.680
Perfect.
