Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,630 --> 00:00:05,350
In the last video, we learned how to retrieve all the rows of the table.
2
00:00:06,280 --> 00:00:11,560
Let us now look at how to retrieve data, which is satisfying a particular specified condition.
3
00:00:12,490 --> 00:00:14,890
Condition is specified using the clause.
4
00:00:15,810 --> 00:00:17,610
Let us see the syntax of this clause.
5
00:00:20,040 --> 00:00:21,360
It starts with select.
6
00:00:21,630 --> 00:00:29,280
You enter all the column names which you want to retrieve from the table name, and then you specify
7
00:00:29,280 --> 00:00:31,860
the condition after the where clause.
8
00:00:33,680 --> 00:00:36,080
Let us look at some examples of these conditions.
9
00:00:38,670 --> 00:00:43,260
Let's say we want to find out if there is any customer who is 25 years old.
10
00:00:44,330 --> 00:00:45,480
This is how we do it.
11
00:00:45,500 --> 00:00:51,020
Select first name from Customer table where age is equal to 25.
12
00:00:51,710 --> 00:00:54,740
This age is equal to 25 will be the condition.
13
00:00:55,010 --> 00:00:58,080
If it is satisfied, we will get a response back.
14
00:00:58,100 --> 00:01:01,130
If it is not, we will get a null response back.
15
00:01:01,430 --> 00:01:03,020
Let us run this query.
16
00:01:06,620 --> 00:01:08,480
Select first name.
17
00:01:10,320 --> 00:01:11,460
From customer table.
18
00:01:17,920 --> 00:01:20,020
Where it is equal to.
19
00:01:20,950 --> 00:01:21,580
25.
20
00:01:27,660 --> 00:01:32,490
Only the customer with first name G is having age 25.
21
00:01:33,550 --> 00:01:39,370
If you wanted the distinct values, you could have used select distinct roles that would have given
22
00:01:39,370 --> 00:01:41,170
you distinct response.
23
00:01:41,200 --> 00:01:42,130
Let us do that.
24
00:01:47,900 --> 00:01:48,420
Run it.
25
00:01:48,500 --> 00:01:52,220
You see, only one G returned.
26
00:01:53,860 --> 00:01:58,510
Now, if you want to put a condition of age more than 25.
27
00:01:59,480 --> 00:02:03,710
You can just change this equal to sign to greater than sign.
28
00:02:06,370 --> 00:02:07,720
And then run this query.
29
00:02:11,270 --> 00:02:14,780
The condition that we apply right now is numeric and correct.
30
00:02:15,320 --> 00:02:20,690
That is, we are checking if that particular number is equal to or more than 25 or not.
31
00:02:21,650 --> 00:02:25,820
We can put conditions on textual variables also.
32
00:02:26,830 --> 00:02:28,720
You can match the variable.
33
00:02:28,750 --> 00:02:35,590
So, for example, if you want to get all the information of the customer with first name G.
34
00:02:36,540 --> 00:02:38,190
We will select star.
35
00:02:43,450 --> 00:02:45,700
From customer table.
36
00:02:50,000 --> 00:02:50,630
We're.
37
00:02:52,690 --> 00:02:53,530
First name.
38
00:03:01,900 --> 00:03:02,410
The.
39
00:03:03,890 --> 00:03:04,580
This query.
40
00:03:10,020 --> 00:03:17,820
You can see all the columns have been retrieved, but only those rows we have got as a result which
41
00:03:17,820 --> 00:03:19,710
have first name as G.
42
00:03:20,980 --> 00:03:28,870
One more thing you can note is in the previous query, we retrieved only first name, but we put a check
43
00:03:28,870 --> 00:03:30,670
on the Age column.
44
00:03:30,670 --> 00:03:32,530
So these two columns were different.
45
00:03:32,560 --> 00:03:35,140
This is allowed by PostgreSQL.
46
00:03:36,180 --> 00:03:43,080
So some variants of the SQL Server would make it necessary that the column on which you put your condition
47
00:03:43,080 --> 00:03:45,420
is part of your selected columns.
48
00:03:46,360 --> 00:03:50,590
But the way we wrote the query that is allowed by PostgreSQL.
49
00:03:51,010 --> 00:03:54,430
So in this video we learned how to put condition while retrieving data.
50
00:03:55,090 --> 00:04:01,030
Next, we will learn how to put multiple conditions at the same time in the same query using an and
51
00:04:01,030 --> 00:04:01,810
or operator.
4246
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.