1 00:00:00,130 --> 00:00:03,230 Let's talk about the R and CRUD, which is read. 2 00:00:03,240 --> 00:00:07,740 How do we retrieve or read data that's already in a table? 3 00:00:07,980 --> 00:00:09,900 We kind of know the answer. 4 00:00:09,900 --> 00:00:11,070 We use select. 5 00:00:11,070 --> 00:00:12,360 We've seen this before. 6 00:00:12,360 --> 00:00:14,430 I just used it in the previous video. 7 00:00:14,430 --> 00:00:19,080 We've only seen one flavor of select though, which is select Star from a table. 8 00:00:19,080 --> 00:00:20,400 Select star from. 9 00:00:20,400 --> 00:00:24,780 I think I still have my employees in here, Select Star from Cats. 10 00:00:24,780 --> 00:00:27,000 We've been using it just to check our work. 11 00:00:27,000 --> 00:00:33,630 That is an example of reading from a table, selecting rows from a table and viewing them. 12 00:00:33,630 --> 00:00:33,870 Right? 13 00:00:33,870 --> 00:00:37,950 It's retrieving information, but there's a lot more to this select. 14 00:00:37,950 --> 00:00:39,600 Sometimes this is what we want. 15 00:00:39,600 --> 00:00:41,070 Select Star from Cats. 16 00:00:41,070 --> 00:00:49,230 In this star, the select star from Cats is a way of saying, Give me all the columns for this table. 17 00:00:49,230 --> 00:00:53,520 Give me every single column, and in this case, for all the rows. 18 00:00:53,790 --> 00:00:59,610 So that's why we see cat ID, name, breed and age or ID last name, first name, middle name, age, 19 00:00:59,610 --> 00:01:00,420 current status. 20 00:01:00,420 --> 00:01:01,890 Those are all of the columns. 21 00:01:01,890 --> 00:01:03,390 That's what that star does. 22 00:01:03,720 --> 00:01:05,760 But we don't have to get all the columns. 23 00:01:05,760 --> 00:01:09,090 We can actually narrow down what we want to get back. 24 00:01:09,090 --> 00:01:14,160 We can say, I only want name, select name from cats. 25 00:01:14,160 --> 00:01:14,910 Let's try it. 26 00:01:15,570 --> 00:01:17,520 So let me do Star just once again. 27 00:01:17,520 --> 00:01:21,810 So we have that up top and then let's select name from Cats. 28 00:01:22,020 --> 00:01:22,890 It has to match. 29 00:01:22,890 --> 00:01:26,100 Of course, that has to be spelled the same as one of these column names. 30 00:01:26,460 --> 00:01:29,580 And now I'm only getting this portion of the table. 31 00:01:29,580 --> 00:01:33,210 Well, I'm highlighting everything, but I'm trying to highlight this section here. 32 00:01:33,420 --> 00:01:35,910 Names only the names. 33 00:01:36,090 --> 00:01:39,690 We could also, of course, do select age from cats. 34 00:01:39,690 --> 00:01:40,560 Let's try that. 35 00:01:40,980 --> 00:01:44,490 Select age from cats. 36 00:01:44,490 --> 00:01:48,540 Technically, I keep going back to make sure I have all uppercase, all lowercase. 37 00:01:48,540 --> 00:01:52,170 It doesn't actually matter as we've seen, but this just looks ugly. 38 00:01:52,170 --> 00:01:54,480 I don't want you to have to endure such ugly code. 39 00:01:54,480 --> 00:02:01,620 But anyway, we get all of the ages and only the ages, so maybe not that helpful on its own, but this 40 00:02:01,620 --> 00:02:03,210 is something that is helpful. 41 00:02:03,240 --> 00:02:08,340 Let's say that eventually we want to find the average age, the oldest age, the youngest age. 42 00:02:08,340 --> 00:02:12,780 We can work with just ages using select age. 43 00:02:12,900 --> 00:02:15,540 Right now, though, we can't do any of those operations. 44 00:02:15,540 --> 00:02:21,270 So we're simply retrieving all of the ages so we also can combine multiple columns. 45 00:02:21,270 --> 00:02:23,070 I could get name and age. 46 00:02:23,070 --> 00:02:27,270 I just separated, separate them by commas or with commas. 47 00:02:27,420 --> 00:02:31,020 So let's do select name Common age from cats. 48 00:02:31,020 --> 00:02:33,810 How am I missing that uppercase M every time? 49 00:02:34,080 --> 00:02:35,100 And there we go. 50 00:02:35,130 --> 00:02:43,230 Only the name and the age or select name and breed from cats. 51 00:02:43,230 --> 00:02:47,820 Now we only get the name and the corresponding breed columns for every row. 52 00:02:48,390 --> 00:02:50,640 So if we do select star, just one. 53 00:02:50,640 --> 00:02:53,700 One more reminder that gives us all the columns. 54 00:02:53,700 --> 00:02:56,550 And you may have four really complicated tables. 55 00:02:56,550 --> 00:02:59,430 You might actually have dozens of columns, if not more. 56 00:02:59,610 --> 00:03:04,290 So when you do a select star, you won't even be able to see all of the columns, print it out easily. 57 00:03:04,290 --> 00:03:09,090 So sometimes it's just nice to slim things down to the actual columns you care about. 58 00:03:09,090 --> 00:03:10,470 That's it for this video. 59 00:03:10,470 --> 00:03:13,590 And the next one, we've got some additional syntax for select.