1 00:00:00,090 --> 00:00:08,340 So we're moving on to the R of crud, which is read how do we retrieve and search data from a database? 2 00:00:08,580 --> 00:00:10,440 And we've actually already seen this. 3 00:00:10,980 --> 00:00:13,230 The magic command is select. 4 00:00:13,800 --> 00:00:17,850 So remember when we were doing this earlier, select star from Cats? 5 00:00:17,850 --> 00:00:21,150 I told you not to worry about it too much because we'd spend more time on it. 6 00:00:21,150 --> 00:00:27,630 And it was really just something that we needed to have to check our work at at that time when we were 7 00:00:27,630 --> 00:00:31,770 inserting data, but we didn't actually talk about how it works, what the star means. 8 00:00:32,280 --> 00:00:33,810 That's what we're going to do now. 9 00:00:34,170 --> 00:00:41,370 So the star in select star from Cats means give me all the columns in the cat's table. 10 00:00:42,390 --> 00:00:45,750 So we're asking for the Cats table. 11 00:00:45,750 --> 00:00:47,160 That's the from cats. 12 00:00:47,310 --> 00:00:50,880 And in that table we just want everything that we have. 13 00:00:50,880 --> 00:00:55,230 So in our case that means cat ID, name, age and breed. 14 00:00:55,230 --> 00:00:57,840 We want all of them coming back to us. 15 00:00:57,840 --> 00:00:59,190 So let's do that now. 16 00:01:00,210 --> 00:01:04,260 Select star from Cats. 17 00:01:05,880 --> 00:01:14,550 You can see we get cat ID, name, breed and age and we also get every single cat no one is missing. 18 00:01:14,550 --> 00:01:16,290 These are the seven that we inserted. 19 00:01:16,650 --> 00:01:22,440 So that's the basics of Select Star, which you'll use often just to check things out. 20 00:01:22,530 --> 00:01:28,440 But we can also get more specific about what data we want back, which is where the select expression 21 00:01:28,440 --> 00:01:29,070 comes in. 22 00:01:29,610 --> 00:01:33,030 Basically, there's a way for us to specify what columns we want. 23 00:01:33,030 --> 00:01:39,450 In particular, I only want the ID or I only want cats names and age, but not the breed. 24 00:01:40,170 --> 00:01:47,670 So to do that, rather than saying Select Star, we can do things like select name from cats. 25 00:01:47,880 --> 00:01:54,600 And if we do that select name from Cats, what do you think the table will look like? 26 00:01:55,860 --> 00:02:01,380 It looks like this we only get name, so it gives us all seven names, but nothing else. 27 00:02:03,330 --> 00:02:04,260 We could also do. 28 00:02:04,260 --> 00:02:06,120 Select Age from Cats. 29 00:02:12,500 --> 00:02:14,350 And hopefully this is what you expected. 30 00:02:14,360 --> 00:02:21,200 We just get a bunch of ages and just to hammer at home here, we could also do a select let's do cat 31 00:02:21,200 --> 00:02:28,340 ID from cats and we get one, two, three, four, five, six, seven. 32 00:02:29,540 --> 00:02:31,040 So that's useful enough. 33 00:02:31,040 --> 00:02:35,930 But oftentimes we want more than one piece of data, but we don't want everything. 34 00:02:36,680 --> 00:02:39,440 And that's where this comma separated list comes in. 35 00:02:39,440 --> 00:02:41,990 So this whole thing is the select expression. 36 00:02:42,110 --> 00:02:45,680 We're saying select name and age from cats. 37 00:02:46,360 --> 00:02:47,890 So we can try it now. 38 00:02:48,490 --> 00:02:53,440 Select name, comma, age from cats. 39 00:02:53,650 --> 00:02:54,370 And what do you think? 40 00:02:54,370 --> 00:02:54,970 We'll see. 41 00:02:56,380 --> 00:03:00,100 So we get a table with name and age returned back. 42 00:03:00,730 --> 00:03:01,840 So there's no limit on that. 43 00:03:01,840 --> 00:03:07,690 We could do name, age, comma, cat ID, comma, breed, which would be the same thing as select star. 44 00:03:07,960 --> 00:03:12,910 We could do name, age and breed or cat ID and name and age and so on. 45 00:03:12,910 --> 00:03:13,570 I think you get it. 46 00:03:13,570 --> 00:03:16,180 We can mix and match whatever fields we want back. 47 00:03:16,690 --> 00:03:24,490 So just to illustrate my point, let's do a select cat ID, comma, name, comma, age from cat and 48 00:03:24,490 --> 00:03:31,660 we hit enter and we get those three fields notice we're missing breed, but we could just go add that 49 00:03:31,660 --> 00:03:32,530 in if we wanted 50 00:03:35,170 --> 00:03:37,390 and notice that the order matters. 51 00:03:37,390 --> 00:03:40,870 So I said cat ID, then name, then age, then breed. 52 00:03:41,140 --> 00:03:42,370 And that's what we get. 53 00:03:42,670 --> 00:03:44,770 But if I just did a select star, 54 00:03:47,800 --> 00:03:52,630 it uses the default order, which is cat ID, name, breed and then age, which is just how we entered 55 00:03:52,630 --> 00:03:54,220 it when we created the table. 56 00:03:54,340 --> 00:04:03,220 So I could reverse it if I wanted to by select age, then breed, then name, then cat ID from cats 57 00:04:04,030 --> 00:04:05,050 and there we go. 58 00:04:06,070 --> 00:04:11,410 So that's pretty much all there is to the select expression for now at least, where we're just specifying 59 00:04:11,410 --> 00:04:17,170 exactly which columns we want or we can default and use the star which will give us all columns.