WEBVTT

1
00:00:00.100 --> 00:00:01.310
<v Instructor>Hi guys and welcome back.</v>

2
00:00:01.310 --> 00:00:03.140
In this video we're going to deconstruct

3
00:00:03.140 --> 00:00:05.820
the Select statement for you.

4
00:00:05.820 --> 00:00:07.110
Here we've got an example,

5
00:00:07.110 --> 00:00:10.960
SELECT first_name, surname FROM users.

6
00:00:10.960 --> 00:00:12.820
The first part tells the database

7
00:00:12.820 --> 00:00:14.950
that we want to find and retrieve data.

8
00:00:14.950 --> 00:00:17.140
That's what the SELECT is for.

9
00:00:17.140 --> 00:00:20.730
Then the columns that we want to retrieve data from,

10
00:00:20.730 --> 00:00:24.950
or what we want the final result set to contain.

11
00:00:24.950 --> 00:00:26.830
And in the final result set, we're gonna get the

12
00:00:26.830 --> 00:00:31.230
first_name and surname columns of the users table.

13
00:00:31.230 --> 00:00:34.930
Note that, if the users table had five columns, let's say,

14
00:00:34.930 --> 00:00:37.750
we would only get data from the first_name

15
00:00:37.750 --> 00:00:39.610
and surname columns.

16
00:00:39.610 --> 00:00:41.670
There's a lot more to do with SELECT.

17
00:00:41.670 --> 00:00:43.580
We can filter the selected data

18
00:00:43.580 --> 00:00:46.240
so that we only get rows with certain values,

19
00:00:46.240 --> 00:00:48.810
and we can use the WHERE clause for that.

20
00:00:48.810 --> 00:00:49.870
We're gonna use it later on,

21
00:00:49.870 --> 00:00:51.690
We're gonna learn more about that.

22
00:00:51.690 --> 00:00:54.930
We can also select data from multiple tables at once

23
00:00:54.930 --> 00:00:57.210
and we're gonna use JOIN for that,

24
00:00:57.210 --> 00:00:59.140
we're going to learn more about that later on.

25
00:00:59.140 --> 00:01:01.850
This is for what we spoke about earlier on in the course,

26
00:01:01.850 --> 00:01:06.350
regarding Relational Data, we'll be using JOINs to do that.

27
00:01:06.350 --> 00:01:08.980
All right, let's go and write some SELECT statements

28
00:01:08.980 --> 00:01:11.050
over in the Database Viewer.

29
00:01:11.050 --> 00:01:13.990
All right, let's go into DB Browser and start looking at

30
00:01:13.990 --> 00:01:17.540
how we can retrieve data using SELECT queries.

31
00:01:17.540 --> 00:01:20.430
Here I'm in the Browse Data tab at the moment and

32
00:01:20.430 --> 00:01:23.480
you can see I've got five rows of data in my users table.

33
00:01:23.480 --> 00:01:27.140
We're gonna use this test data to run our queries against.

34
00:01:27.140 --> 00:01:29.700
If you want to insert some test data into your table,

35
00:01:29.700 --> 00:01:32.670
pause the video now and do that, as well.

36
00:01:32.670 --> 00:01:34.470
Let's go over to execute SEQUEL,

37
00:01:34.470 --> 00:01:37.520
and here we're going to start with a SELECT.

38
00:01:37.520 --> 00:01:39.440
Again, this tells SQLite that we want to

39
00:01:39.440 --> 00:01:40.980
start retrieving data.

40
00:01:40.980 --> 00:01:44.350
The next part of the query must be the columns

41
00:01:44.350 --> 00:01:46.150
that we want to retrieve.

42
00:01:46.150 --> 00:01:48.720
So, for example, first_name and surname.

43
00:01:48.720 --> 00:01:51.440
We don't have to put brackets around these,

44
00:01:51.440 --> 00:01:53.790
just like that is fine.

45
00:01:53.790 --> 00:01:57.870
Then FROM users tells SQLite that this is a table

46
00:01:57.870 --> 00:02:01.780
we want to retrieve data for these columns from.

47
00:02:01.780 --> 00:02:04.610
So if we run this, you can see now down here,

48
00:02:04.610 --> 00:02:08.750
we've got our five rows retrieved.

49
00:02:08.750 --> 00:02:11.280
You can just retrieve data from one column, of course,

50
00:02:11.280 --> 00:02:13.070
and then you just get that column back

51
00:02:13.070 --> 00:02:15.770
for all the rows in the table.

52
00:02:15.770 --> 00:02:19.010
And, if you use the asterisk, or the * sign,

53
00:02:19.010 --> 00:02:21.800
you can retrieve data from all columns.

54
00:02:21.800 --> 00:02:23.920
At the moment, this looks the same as earlier on,

55
00:02:23.920 --> 00:02:26.110
but if you had more columns, then these would all

56
00:02:26.110 --> 00:02:27.683
show up when you use the star.

57
00:02:28.620 --> 00:02:30.850
Like we mentioned earlier, you can filter the data,

58
00:02:30.850 --> 00:02:32.540
and you can select data from multiple tables.

59
00:02:32.540 --> 00:02:35.010
We're going to learn more about that as we move on

60
00:02:35.010 --> 00:02:36.280
through the course.

61
00:02:36.280 --> 00:02:37.700
Thank you for watching this video.

62
00:02:37.700 --> 00:02:39.313
I'll see you in the next one.

