Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,024 --> 00:00:04,352
Till now, we have seen how to filter and sort results
1
2
00:00:05,120 --> 00:00:05,632
Now
2
3
00:00:05,888 --> 00:00:07,680
We'll learn how to limit the
3
4
00:00:07,936 --> 00:00:08,704
Number of
4
5
00:00:09,216 --> 00:00:11,264
Rows that you are getting in a resultset
5
6
00:00:12,032 --> 00:00:13,056
Why it is important
6
7
00:00:13,568 --> 00:00:16,384
Sometimes our server has over million records
7
8
00:00:16,896 --> 00:00:20,480
And when we are trying to retrieve it it will take a lot of time
8
9
00:00:21,248 --> 00:00:24,576
So to limit the number of rows that you get in your result set
9
10
00:00:24,832 --> 00:00:25,856
We'll be using the
10
11
00:00:26,112 --> 00:00:27,136
Limit statement
11
12
00:00:27,904 --> 00:00:30,464
This is the syntax to use the limit statement
12
13
00:00:31,488 --> 00:00:34,304
Select the column names that you want from the table name
13
14
00:00:34,560 --> 00:00:36,352
Specific any condition if any
14
15
00:00:36,608 --> 00:00:37,120
Then
15
16
00:00:37,376 --> 00:00:39,936
You can order the results if you want to
16
17
00:00:40,192 --> 00:00:41,984
Then you specify limit
17
18
00:00:42,496 --> 00:00:45,824
And then you give the row count, the number of rows that you want
18
19
00:00:46,848 --> 00:00:47,872
For example
19
20
00:00:48,128 --> 00:00:50,688
If you want to find out the top eight
20
21
00:00:50,944 --> 00:00:53,504
Most aged customers in your database
21
22
00:00:54,784 --> 00:00:55,808
How do you do that
22
23
00:00:56,064 --> 00:00:57,600
We'll select the customers
23
24
00:00:57,856 --> 00:01:00,928
With age > 25 that's a condition that is not
24
25
00:01:01,184 --> 00:01:02,208
Necessary but
25
26
00:01:02,464 --> 00:01:03,488
I have Just put it
26
27
00:01:04,000 --> 00:01:09,632
Then you will order it in the descending order of age because we want the customer to have the maximum age
27
28
00:01:10,400 --> 00:01:14,496
Then we'll put a limit of 8 so it will give back only 8 customers
28
29
00:01:15,264 --> 00:01:17,824
Let's go and write this in the PG admin interface
29
30
00:01:18,080 --> 00:01:21,920
I am starting with the
30
31
00:01:22,432 --> 00:01:25,248
Limit lecture
31
32
00:01:26,784 --> 00:01:28,832
Select
32
33
00:01:29,088 --> 00:01:34,208
Star
33
34
00:01:34,720 --> 00:01:38,560
where Age is greater than 25
34
35
00:01:42,144 --> 00:01:48,288
Order by age descending
35
36
00:01:49,312 --> 00:01:52,640
Limit, we only need 8 customers so 8
36
37
00:01:53,408 --> 00:01:54,432
We run it
37
38
00:01:55,200 --> 00:01:55,968
You can see
38
39
00:01:56,480 --> 00:01:58,016
Only 8
39
40
00:01:59,296 --> 00:02:00,576
Rows are returned
40
41
00:02:01,344 --> 00:02:04,416
Others are not return and the age of customer
41
42
00:02:04,672 --> 00:02:05,696
is the maximum
42
43
00:02:06,720 --> 00:02:09,024
So it was arranged in descending order
43
44
00:02:09,280 --> 00:02:12,352
And after that only top 8 rows were returned
44
45
00:02:14,400 --> 00:02:14,912
Now
45
46
00:02:15,680 --> 00:02:16,704
IF you want to get
46
47
00:02:16,960 --> 00:02:17,472
The
47
48
00:02:17,728 --> 00:02:19,776
Customers who have the least age
48
49
00:02:21,056 --> 00:02:22,592
We'll use the same query
49
50
00:02:22,848 --> 00:02:25,408
We'll just arrange them in the ascending order
50
51
00:02:25,920 --> 00:02:28,480
And we'll change the limit to 10 if you want to
51
52
00:02:28,736 --> 00:02:30,528
Find out 10 customers
52
53
00:02:31,040 --> 00:02:34,624
So we'll write select star from customer
53
54
00:02:40,256 --> 00:02:45,120
We put the condition of 25 also so that
54
55
00:02:45,376 --> 00:02:46,400
All the customers
55
56
00:02:47,680 --> 00:02:51,520
Who have age more than 25
56
57
00:02:52,032 --> 00:02:54,592
And starting with
57
58
00:02:54,848 --> 00:02:56,384
The minimum age
58
59
00:02:59,968 --> 00:03:02,272
Limit 10, so it will give me the top 10 customers
59
60
00:03:04,832 --> 00:03:06,368
These are the 10 customers
60
61
00:03:07,392 --> 00:03:09,440
Whose age is Greater than 25
61
62
00:03:10,464 --> 00:03:13,536
So all of the customers have 26 years of age
62
63
00:03:14,304 --> 00:03:16,096
And it is arranged in ascending order
63
64
00:03:17,376 --> 00:03:19,168
And only 10 records are written
64
65
00:03:19,680 --> 00:03:21,728
So that is how we using limit statement
65
66
00:03:22,240 --> 00:03:24,800
It will limit the number of records that we get back
66
67
00:03:25,312 --> 00:03:26,080
This
67
68
00:03:26,336 --> 00:03:29,920
Statment will be very handy when you are handling large data sets
68
69
00:03:30,432 --> 00:03:33,248
In the next lecture we'll learn how to give
69
70
00:03:33,504 --> 00:03:34,528
Second names or
70
71
00:03:34,784 --> 00:03:37,344
Aliases to the column names
5197
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.