WEBVTT 1 00:00:00.000 --> 00:00:01.290 Hi, and welcome back. 2 00:00:01.290 --> 00:00:03.840 In this video, we're talking about extracting data 3 00:00:03.840 --> 00:00:07.270 from our tables using the Select statement. 4 00:00:08.970 --> 00:00:11.910 In this table, we've got four columns, id, name, 5 00:00:11.910 --> 00:00:15.270 and address, and four rows going from one to four. 6 00:00:16.320 --> 00:00:18.840 When we want to use a Select statement, 7 00:00:18.840 --> 00:00:21.690 we have to specify three important things. 8 00:00:21.690 --> 00:00:24.720 The first one that we want to actually select data 9 00:00:24.720 --> 00:00:27.510 and not insert it, for example. 10 00:00:27.510 --> 00:00:30.710 The second one, we have to say what columns we want to get 11 00:00:30.710 --> 00:00:32.210 in our results, 12 00:00:32.210 --> 00:00:34.610 whether it's the id column, the name column, 13 00:00:34.610 --> 00:00:36.620 or the address column, or all of them, 14 00:00:36.620 --> 00:00:37.970 or any combination of them. 15 00:00:38.970 --> 00:00:41.170 And finally, we also have to say what table 16 00:00:41.170 --> 00:00:43.410 we want to get our data from. 17 00:00:43.410 --> 00:00:45.360 In this case, let's get it from this table here 18 00:00:45.360 --> 00:00:47.190 which I'm going to call people. 19 00:00:49.090 --> 00:00:52.380 So this would be a Select statement. 20 00:00:52.380 --> 00:00:55.280 First the Select keyword, 21 00:00:55.280 --> 00:01:00.130 then a star which means all columns, then the keyword from, 22 00:01:00.130 --> 00:01:02.780 and then the table that we want to select from. 23 00:01:02.780 --> 00:01:06.620 So this means select all the columns from people. 24 00:01:06.620 --> 00:01:09.250 And it would give us a result set that looks exactly 25 00:01:09.250 --> 00:01:11.140 like the original table. 26 00:01:11.140 --> 00:01:13.550 As you can see, it looks the same, three columns, 27 00:01:13.550 --> 00:01:16.750 four rows, all the data is there. 28 00:01:16.750 --> 00:01:21.030 Notice how we've not had to specify what rows we want. 29 00:01:21.030 --> 00:01:24.050 We're only specifying that we want all the columns. 30 00:01:24.050 --> 00:01:25.620 That's what the star means. 31 00:01:25.620 --> 00:01:28.490 By default, the Select statement will select 32 00:01:28.490 --> 00:01:29.620 all of the rows. 33 00:01:29.620 --> 00:01:32.070 So, all of the data in your table. 34 00:01:32.070 --> 00:01:33.930 And we are going to learn how to limit that, 35 00:01:33.930 --> 00:01:36.700 how to get only some rows very soon, 36 00:01:36.700 --> 00:01:38.100 in a couple of video's time. 37 00:01:38.990 --> 00:01:41.160 Let's have a look at another example where we won't select 38 00:01:41.160 --> 00:01:43.600 all of the columns, we'll just select a couple of them. 39 00:01:43.600 --> 00:01:45.300 And, this would be this. 40 00:01:45.300 --> 00:01:48.690 Select name, address from people. 41 00:01:48.690 --> 00:01:52.190 And that's of course, going to give us two columns, 42 00:01:52.190 --> 00:01:53.870 name and the address. 43 00:01:53.870 --> 00:01:57.280 Notice how the id column is not present in our result set 44 00:01:57.280 --> 00:02:00.120 because we've not requested it with the Select statement. 45 00:02:01.720 --> 00:02:04.270 Of course, we could select id and name if we wanted 46 00:02:04.270 --> 00:02:06.910 for example, and that would give us again, two columns, 47 00:02:06.910 --> 00:02:09.810 id and name and it wouldn't give us back the address. 48 00:02:09.810 --> 00:02:12.410 Totally fine, you can do this if you want. 49 00:02:12.410 --> 00:02:14.550 Notice how the general formula here, 50 00:02:14.550 --> 00:02:17.400 the structure or the syntax of the statement 51 00:02:17.400 --> 00:02:19.680 is first of all, Select. 52 00:02:19.680 --> 00:02:22.540 Then, the columns you want, whether it's a star 53 00:02:22.540 --> 00:02:25.170 or whether it's a comma separated column names. 54 00:02:25.170 --> 00:02:27.810 Then the keyword from, and finally, the table. 55 00:02:29.370 --> 00:02:31.210 You can also merge them together so you can 56 00:02:31.210 --> 00:02:34.480 select id, star if you want. 57 00:02:34.480 --> 00:02:37.280 But this is a pretty silly thing to do in my opinion. 58 00:02:37.280 --> 00:02:39.890 I'm just telling you this because you can do this. 59 00:02:39.890 --> 00:02:42.590 But again, you get double the id columns, 60 00:02:42.590 --> 00:02:45.090 which is not very useful in most scenarios, 61 00:02:45.090 --> 00:02:46.310 probably any scenario. 62 00:02:47.200 --> 00:02:48.920 But none the less, it's something you can do. 63 00:02:48.920 --> 00:02:51.520 Again, the star just gets replaced by 64 00:02:51.520 --> 00:02:54.090 all of the column names in your table. 65 00:02:54.090 --> 00:02:56.900 So of course, you can use a star as well as 66 00:02:56.900 --> 00:02:58.060 other column names if you want. 67 00:02:58.060 --> 00:02:59.460 And this is gonna come in handy. 68 00:02:59.460 --> 00:03:00.560 The fact that we can do this 69 00:03:00.560 --> 00:03:02.370 is gonna come in handy later on. 70 00:03:02.370 --> 00:03:05.100 Doing this with single table is not so handy. 71 00:03:06.590 --> 00:03:08.030 Okay, that's it for this video. 72 00:03:08.030 --> 00:03:09.480 I'll see you in the next one.