WEBVTT

00:07.610 --> 00:10.610
I will call you back again to another video lecture in MySQL.

00:10.610 --> 00:15.470
And in this lecture, let's go ahead and look at the limit clause in MySQL.

00:16.190 --> 00:16.520
All right.

00:16.520 --> 00:17.360
So let's go ahead.

00:17.360 --> 00:21.440
And now look at a clause known as the limit clause.

00:21.440 --> 00:29.300
And this is used to limit the number of records in MySQL for people working with a large amount of data.

00:29.300 --> 00:32.450
So this can be used to display large data on pages.

00:32.450 --> 00:35.120
And these pages are known as pagination.

00:35.270 --> 00:39.350
Let's go ahead and see from a table the students table below.

00:39.380 --> 00:47.270
Let's go ahead and select all from students.

00:47.270 --> 00:49.940
And then we go ahead and limit that.

00:49.970 --> 00:52.340
That's why I say limit.

00:52.370 --> 00:54.050
You can see that limit is a keyword.

00:54.050 --> 00:58.130
And first of all I will limit that to just one.

00:58.400 --> 00:58.820
All right.

00:58.850 --> 01:00.860
And as it kills this let's see what happens.

01:00.860 --> 01:05.580
So it goes on to get in just one of the very first one.

01:05.580 --> 01:09.540
So imagine you want to check out maybe the second, the third, the fourth.

01:09.540 --> 01:11.520
And you just want to get only one.

01:11.520 --> 01:14.610
So if you go ahead and check two we will go to public.

01:14.640 --> 01:16.170
Two go ahead and check it out.

01:16.200 --> 01:18.060
We have two records shown.

01:18.060 --> 01:22.650
So in that case if we also do three, you go ahead and get three records shown.

01:22.650 --> 01:29.700
And in that way if you also do four, you get four records shown and so on till the last one.

01:30.090 --> 01:31.500
And that is it.

01:31.500 --> 01:35.130
So this is about limit uh, class.

01:35.130 --> 01:41.880
And um, you can combine the limit class with the order by clause in a way to do that the score head

01:41.880 --> 01:44.880
and say we want to combine that.

01:44.910 --> 01:51.300
I'll go ahead and say the order by, and then we can select maybe the first name or the last name or

01:51.300 --> 01:53.490
department or GP or a road date.

01:53.520 --> 01:58.020
Let's go ahead and select the first underscore name.

01:58.020 --> 02:02.130
And then we're going to limit that by just maybe three.

02:02.430 --> 02:04.520
And let's go ahead and check it out.

02:05.600 --> 02:12.860
So we selected that and it populates based on the ascending order.

02:12.890 --> 02:14.600
That is why it is not arranged.

02:14.600 --> 02:20.750
So looking at the student's ID and by order you can see that one would discuss order previously.

02:20.750 --> 02:24.710
It's always start by the ascending order that is the default.

02:24.710 --> 02:31.250
So if you want that to be maybe by descending order, what you need to do is order by first name.

02:31.250 --> 02:38.540
Then you go ahead and say the same and then limit three and go ahead and check it out.

02:38.540 --> 02:41.030
So it starts from the descending order.

02:41.030 --> 02:44.960
So you can also increase this to like four or any number just like we did.

02:44.960 --> 02:46.280
And you can see that.

02:46.280 --> 02:52.520
So you can use the order by clause which are in conjunction with the limit clause.

02:52.520 --> 02:55.820
So with limit clause you can also add an offset.

02:55.850 --> 02:58.700
Let's go ahead and say I'm going to remove this.

02:58.700 --> 03:01.730
And then I'll go ahead and remove this.

03:01.730 --> 03:04.100
I'm going to say limit.

03:04.100 --> 03:06.330
And then I'll go ahead and put the offsets.

03:06.360 --> 03:08.370
Maybe I want to start from anyone.

03:08.430 --> 03:14.010
I'm going to say start from the very first one and display just one.

03:14.070 --> 03:16.650
And then it goes on to do this.

03:17.220 --> 03:20.730
Remember that based on the previous one, that is what is still showing.

03:20.760 --> 03:24.510
Go ahead and remove this and let's select Add Table.

03:24.510 --> 03:25.650
And this is our table.

03:25.650 --> 03:28.140
So I'll go ahead and bring back the limits cross again.

03:28.140 --> 03:30.330
So go ahead and say limit.

03:30.330 --> 03:34.950
Then the offset is going to start from let me say starts from three.

03:34.980 --> 03:40.590
That means we want to display barracks and then we want just to be displayed only one.

03:40.590 --> 03:43.890
Then go ahead and show this.

03:44.370 --> 03:44.670
All right.

03:44.670 --> 03:48.900
So the uh the limit start from zero index.

03:48.900 --> 03:50.760
And that is why it moves to the first one.

03:50.760 --> 03:51.870
So I want to display barracks.

03:51.870 --> 03:55.710
I'll go back I change this to two and barrack is shown.

03:55.710 --> 03:58.170
So the very first one is index zero.

03:58.170 --> 04:02.700
So if I go ahead and start from zero it's going to display to as a very first one.

04:02.700 --> 04:05.730
You see that display limit starts from zero.

04:05.760 --> 04:08.150
And now if we want to display like maybe two.

04:08.180 --> 04:12.530
Go ahead and add two and go ahead and display from Peta and then move to Oscar.

04:12.560 --> 04:13.520
That is it.

04:13.550 --> 04:16.730
So I want to start maybe from four.

04:16.760 --> 04:18.020
I showed two numbers.

04:18.050 --> 04:19.640
Only two of the data.

04:19.670 --> 04:20.360
All right.

04:20.390 --> 04:21.620
Go ahead and execute the query.

04:21.620 --> 04:24.080
And I have Mike and Queen.

04:24.080 --> 04:27.350
So you can also increase the move your offsets.

04:27.350 --> 04:29.480
So the very first one here is offset.

04:29.510 --> 04:30.170
Okay.

04:30.200 --> 04:32.900
So go ahead and check it out.

04:32.900 --> 04:34.970
So offset is the very first one.

04:34.970 --> 04:37.940
And then the limit is the second one.

04:37.940 --> 04:43.220
So the second condition is the limit while the first condition is the offset where you're going to start.

04:43.220 --> 04:47.750
So go ahead and check out these and you can set another WhatsApp file is very interesting.

04:47.750 --> 04:48.800
So play around with it.

04:48.800 --> 04:52.190
And if you have any question go ahead and use the question answer section.

04:52.190 --> 04:54.680
And I'm going to get back to you as soon as possible.

04:54.950 --> 04:55.940
Thank you so much.

04:55.940 --> 04:58.910
And I'm going to see you in the next video lecture.
