Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,730 --> 00:00:06,560
In the last video, we learned how to apply one condition while retrieving data.
2
00:00:07,840 --> 00:00:12,310
Let us now look at how to retrieve data, which is satisfying multiple conditions.
3
00:00:13,050 --> 00:00:18,480
Multiple conditions can be applied using the and and or operators.
4
00:00:19,800 --> 00:00:25,200
And operators used when we want that, all of the conditions are satisfied.
5
00:00:26,610 --> 00:00:31,890
Whereas our operator will be used when we want to retrieve the data with any one of the conditions.
6
00:00:31,890 --> 00:00:32,610
Satisfied.
7
00:00:34,540 --> 00:00:35,920
Let us look at this syntax.
8
00:00:37,080 --> 00:00:42,780
We select columns from table name where this will be the condition one.
9
00:00:43,470 --> 00:00:47,520
After this, if you want to have an and operator, we will write.
10
00:00:47,520 --> 00:00:52,830
And if you want all operator, we will write all and then we will specify the second condition.
11
00:00:53,800 --> 00:00:55,270
We can continue doing so.
12
00:00:55,480 --> 00:00:57,550
We can have a number of conditions.
13
00:00:59,230 --> 00:01:00,460
Let us look at an example.
14
00:01:02,210 --> 00:01:04,460
If you want to get the customers.
15
00:01:05,230 --> 00:01:09,010
Who's age is between 20 and 30 years.
16
00:01:10,380 --> 00:01:12,810
We can do this by using the and operator.
17
00:01:12,900 --> 00:01:19,890
So these customers will be satisfying the condition that their age is more than 20 years and the age
18
00:01:19,890 --> 00:01:21,150
is less than 30 years.
19
00:01:23,390 --> 00:01:29,060
So we will select first name, last name and age of the customer from customer table, where age is
20
00:01:29,060 --> 00:01:32,720
greater than 20 and age is less than 30.
21
00:01:33,380 --> 00:01:35,600
Let us go and write this in PG admin.
22
00:01:40,220 --> 00:01:41,870
Select first name.
23
00:01:48,040 --> 00:01:49,030
Last name.
24
00:01:50,720 --> 00:01:51,260
From.
25
00:01:53,370 --> 00:01:55,650
Let's add age also.
26
00:02:01,660 --> 00:02:02,530
Customer table.
27
00:02:03,220 --> 00:02:03,850
Where?
28
00:02:07,800 --> 00:02:12,450
It is greater than 20 and it is less than.
29
00:02:13,690 --> 00:02:14,170
30.
30
00:02:17,460 --> 00:02:18,600
And that's when this query.
31
00:02:20,900 --> 00:02:23,870
You can see five records are retrieved.
32
00:02:24,320 --> 00:02:29,690
And age of all these five customers is between 20 and 30.
33
00:02:31,570 --> 00:02:40,210
Now, if we want all the other customers, that is customer whose age is less than 20 or more than 30,
34
00:02:40,780 --> 00:02:42,640
we will be using the auto operator.
35
00:02:42,670 --> 00:02:43,750
Let us write that.
36
00:02:47,830 --> 00:02:48,370
Select.
37
00:02:48,370 --> 00:02:48,850
First name.
38
00:02:48,850 --> 00:02:49,480
Last name.
39
00:02:49,510 --> 00:02:50,170
Age.
40
00:03:17,990 --> 00:03:19,850
The age is less than 20.
41
00:03:20,790 --> 00:03:23,250
Or it is greater than equal to 30.
42
00:03:26,370 --> 00:03:27,440
That's when this.
43
00:03:30,120 --> 00:03:30,900
You can see.
44
00:03:32,730 --> 00:03:38,730
So all the customers who have less than 20 or is less than 30 have been retrieved.
45
00:03:38,760 --> 00:03:41,190
These are the other five rows of the table.
46
00:03:42,730 --> 00:03:44,800
Apart from and and all.
47
00:03:45,250 --> 00:03:47,740
There is one more logical operator called not.
48
00:03:49,670 --> 00:03:52,070
Not operator is used to negate a condition.
49
00:03:52,960 --> 00:03:54,010
So last time.
50
00:03:55,010 --> 00:03:59,470
When we found out that there is one customer with age 25.
51
00:03:59,480 --> 00:04:04,190
If you want to find out all the other customers you can just use not.
52
00:04:04,980 --> 00:04:11,460
So let us write this example where we are finding out all the customers with is not is equal to 25.
53
00:04:25,710 --> 00:04:26,880
From customer table.
54
00:04:26,880 --> 00:04:27,450
Where?
55
00:04:30,870 --> 00:04:31,560
We are not.
56
00:04:31,560 --> 00:04:33,930
Age is equal to 25.
57
00:04:37,050 --> 00:04:40,410
So this will give us all the customers.
58
00:04:41,360 --> 00:04:43,180
We did not equal to five.
59
00:04:43,700 --> 00:04:47,780
So last time, if you remember, we got three records.
60
00:04:48,050 --> 00:04:49,560
Our table has total ten records.
61
00:04:49,580 --> 00:04:51,080
These are the other seven records.
62
00:04:52,750 --> 00:04:58,270
Now you can use this knot operator along with and another operator.
63
00:04:58,540 --> 00:05:05,800
So, for example, if you want to specify that you want to get all the customers with age not equal
64
00:05:05,800 --> 00:05:10,770
to 25 and the customer's first name should not be G.
65
00:05:12,600 --> 00:05:16,020
So both of these conditions can be applied simultaneously.
66
00:05:16,290 --> 00:05:18,210
We will select start.
67
00:05:19,440 --> 00:05:20,850
From customer table.
68
00:05:21,690 --> 00:05:22,350
We're.
69
00:05:24,110 --> 00:05:25,670
Not age is equal to 25.
70
00:05:28,480 --> 00:05:28,990
They're not.
71
00:05:28,990 --> 00:05:31,000
Age is equal to 25.
72
00:05:33,130 --> 00:05:33,670
And.
73
00:05:34,470 --> 00:05:35,040
Not.
74
00:05:36,020 --> 00:05:36,920
First name.
75
00:05:39,750 --> 00:05:40,650
Is equal to.
76
00:05:43,630 --> 00:05:43,950
J.
77
00:05:45,850 --> 00:05:46,820
You run this.
78
00:05:48,280 --> 00:05:52,330
See, the J records are also removed.
79
00:05:52,600 --> 00:05:54,670
Now we have only four records.
80
00:05:54,670 --> 00:05:55,390
And the result?
81
00:05:56,890 --> 00:06:03,100
So these are the three logical operators which help us put multiple conditions in the same query.
6130
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.