1 00:00:00,210 --> 00:00:00,550 Okay. 2 00:00:00,570 --> 00:00:05,230 So what we've seen so far allows us to specify what columns we want. 3 00:00:05,250 --> 00:00:11,460 Name an age only or only ID, but it still gives us every single result in the table. 4 00:00:11,580 --> 00:00:17,820 So if we have 10,000 users in our database, if we wanted to select one, we don't have a way of doing 5 00:00:17,820 --> 00:00:18,550 that right now. 6 00:00:18,570 --> 00:00:22,200 We only can select all of them, which really is not that useful. 7 00:00:22,350 --> 00:00:26,970 And in fact, most of the time when you're selecting things, you're doing it deliberately and you're 8 00:00:26,970 --> 00:00:28,710 trying to find particular pieces. 9 00:00:28,710 --> 00:00:31,890 You're not just trying to check in on your table, make sure everything's okay. 10 00:00:31,920 --> 00:00:35,400 You're usually trying to, let's say, sign someone in. 11 00:00:35,420 --> 00:00:41,340 It's an application you're trying to verify, find someone by their username and check if their password 12 00:00:41,340 --> 00:00:46,830 matches that they entered into your website or something like that where you're searching for specific 13 00:00:46,830 --> 00:00:47,370 data. 14 00:00:47,550 --> 00:00:51,760 And to do that, we need to use what's known as the where clause. 15 00:00:51,780 --> 00:00:56,300 So it's another magic keyword where, and it allows us to get specific. 16 00:00:56,310 --> 00:01:03,960 It allows us to say, I want all cats who are four years old or I want all cats who are tabbies. 17 00:01:03,990 --> 00:01:05,820 And those are very simple examples. 18 00:01:06,030 --> 00:01:12,080 But later on, throughout this course, we'll continue to expand your arsenal for select and for searching. 19 00:01:12,090 --> 00:01:19,170 You'll be able to do things like I want all cats that are Tabby is between the age of one and two and 20 00:01:19,170 --> 00:01:22,180 whose name starts with the letter B, let's say. 21 00:01:22,200 --> 00:01:24,180 So we'll be able to get much more specific. 22 00:01:24,180 --> 00:01:27,090 But for now we're focusing on the basics. 23 00:01:27,090 --> 00:01:31,740 And as a side note, I want to show you that we will use where all the time. 24 00:01:31,740 --> 00:01:37,230 So it's not just for searching or for selecting, but we'll need to use it when we're updating or deleting 25 00:01:37,230 --> 00:01:42,360 things as well, because unless we're trying to update every single thing or delete every single thing, 26 00:01:42,360 --> 00:01:45,330 usually we want to update something specific. 27 00:01:45,330 --> 00:01:52,860 So we might say, I want to update the cats where their age is too, and I want to make their age three. 28 00:01:53,720 --> 00:01:57,780 Versus I want to update every single cat to have an age of three. 29 00:01:57,800 --> 00:01:59,990 We could be more targeted using where. 30 00:02:00,320 --> 00:02:03,860 So we're going to start by seeing how we use it to select. 31 00:02:03,980 --> 00:02:10,009 So here's an example select star from Cats where age is four. 32 00:02:10,639 --> 00:02:11,810 So notice the syntax. 33 00:02:11,810 --> 00:02:16,130 Here we have our same select star from cats that will give us all cats. 34 00:02:16,400 --> 00:02:19,490 But then we have this where age equals four. 35 00:02:20,180 --> 00:02:28,190 So what this will do is only select the data from the Cats table where the age column is equal to four. 36 00:02:29,060 --> 00:02:37,400 And if we try that now, if we look at our data actually, you'll see we have two cats, Ringo and Egg, 37 00:02:38,330 --> 00:02:40,400 who are both four years old. 38 00:02:40,940 --> 00:02:43,940 So if we do a select star from Cats, you see what we get. 39 00:02:43,940 --> 00:02:53,390 But now if we modify that with our where age equals four semicolon, we only get those two results. 40 00:02:53,390 --> 00:02:59,450 So we still get cat ID, name, breed and age because we use star that tells us the columns. 41 00:02:59,660 --> 00:03:04,040 But now we only have two results because we used where to get specific. 42 00:03:04,490 --> 00:03:09,650 One note notice that when I refer to age here, that is the column age. 43 00:03:09,650 --> 00:03:12,470 So there's no quotes around it, it's just age. 44 00:03:13,580 --> 00:03:15,260 So we can do the same thing here. 45 00:03:15,260 --> 00:03:20,450 But this time I'm using name to drill down or to get specific. 46 00:03:20,450 --> 00:03:24,350 So select star from cat where name is equal to egg. 47 00:03:24,350 --> 00:03:29,150 And notice I use quotes here because it's no longer an integer like ages. 48 00:03:29,840 --> 00:03:32,180 Name is fa cha, it's text. 49 00:03:32,180 --> 00:03:34,760 So we need those quotes so we can try that. 50 00:03:34,760 --> 00:03:35,300 Now. 51 00:03:35,300 --> 00:03:43,760 Select star from cats where name equals egg just like that. 52 00:03:45,230 --> 00:03:50,030 And you notice we get egg cat id, name, breed and age. 53 00:03:50,030 --> 00:03:55,130 One side note while I'm here, you may come across this at some point. 54 00:03:55,220 --> 00:03:58,340 What do you think will happen if I fully capitalize egg? 55 00:04:01,080 --> 00:04:02,190 It still works. 56 00:04:02,670 --> 00:04:07,280 So it's important to note that by default this is case insensitive. 57 00:04:07,290 --> 00:04:13,950 So I could do lowercase g, uppercase g and it still gives me the same data. 58 00:04:14,250 --> 00:04:16,200 So we'll see ways around this later on. 59 00:04:16,470 --> 00:04:22,170 Oftentimes it is useful, though, to not worry about case if you're dealing with things like an email 60 00:04:22,170 --> 00:04:24,840 address where case doesn't actually matter. 61 00:04:24,870 --> 00:04:30,600 So if a user types in their email with a capital letter at the beginning versus lowercase, it should 62 00:04:30,600 --> 00:04:33,950 still be the same email in your database, but we'll talk about that later. 63 00:04:33,960 --> 00:04:37,800 I just wanted to point out that it's a thing, case and sensitivity. 64 00:04:38,010 --> 00:04:40,910 So that's all there is for now to the WHERE clause. 65 00:04:40,920 --> 00:04:43,590 Now there is a lot more that we will be seeing and working with. 66 00:04:43,590 --> 00:04:48,690 Like I mentioned at the beginning of this lesson, we will come back and use where all the time and 67 00:04:48,690 --> 00:04:52,170 in fact we're going to continue to use it for updating and deleting. 68 00:04:52,170 --> 00:04:56,760 Like I said, we need to specify what we want to delete and what we want to update. 69 00:04:57,240 --> 00:05:01,710 But I just want to make it clear we're not done with where there's a lot of add on functionality that 70 00:05:01,710 --> 00:05:03,970 we'll see in ensuing sections. 71 00:05:03,990 --> 00:05:04,740 Perfect.