WEBVTT

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

00:10.580 --> 00:16.520
And in this video lecture, let's go ahead and look at logical operators in MySQL.

00:16.910 --> 00:20.270
So in MySQL we have the logical operators.

00:20.270 --> 00:24.110
And the operators are used to check more than one condition.

00:24.500 --> 00:30.380
So it is very important we learn about it because you are always going to use it to query a table if

00:30.380 --> 00:32.570
we're working in large organizations.

00:32.570 --> 00:38.180
So first of all let me go ahead and add something to our table, the students table which is right before

00:38.210 --> 00:38.810
us.

00:38.810 --> 00:44.450
So I'll go ahead and add a department so it can be able to actually use that here.

00:44.480 --> 00:50.450
So let's go ahead and see what a table and the table want to alter is a students table.

00:50.450 --> 00:54.440
And then we'll go ahead and add another column to that.

00:54.440 --> 00:56.300
So go ahead and add column.

00:56.300 --> 01:05.520
And the column is going to be Department and is going to be involved at a time.

01:05.520 --> 01:08.280
So varchar.

01:08.310 --> 01:08.940
All right.

01:08.940 --> 01:15.450
So I'll let it take just a 20 characters or 30 go.

01:15.480 --> 01:16.590
So 20 is okay.

01:16.590 --> 01:19.620
And I want to place that after the GP.

01:19.650 --> 01:26.430
So we can have a clear demarcation between the first last name and the departments.

01:26.430 --> 01:29.370
So after the GP we then go ahead and place that.

01:29.370 --> 01:34.620
So this guy and say after GP and put a semicolon at the end.

01:34.650 --> 01:40.800
Now let's go ahead and also show our table after we've done that and say select.

01:42.030 --> 01:47.820
So select all from students.

01:47.820 --> 01:49.140
Press semicolon at the end.

01:49.170 --> 01:50.130
Go ahead and run this.

01:50.130 --> 01:51.150
Let's check it out.

01:51.300 --> 01:57.240
And now we have this null and null.

01:57.270 --> 02:03.140
What it means is that we have to go ahead and update this room, because you can see we have added a

02:03.140 --> 02:10.070
column right near the department column, but we don't have any, uh, values in there.

02:10.100 --> 02:12.020
So let's go ahead and update that.

02:12.050 --> 02:14.180
Go ahead and uh remove this.

02:14.180 --> 02:16.220
So can we want to update that.

02:16.460 --> 02:22.580
I'll go ahead and say update student uh table.

02:22.910 --> 02:28.430
So update students and we go ahead and set our department.

02:32.690 --> 02:40.730
So departments should be equal to let me say the first one electronics.

02:43.610 --> 02:53.810
So electronics go ahead and uh say where we are close so we can be able to add that's where the student's

02:54.110 --> 02:58.010
ID is equal to one.

02:58.040 --> 03:00.120
I'll put a semicolon at the end.

03:00.240 --> 03:02.460
And let's go ahead and run this and check it out.

03:02.460 --> 03:05.880
So we have added electronics to pizza George.

03:06.270 --> 03:08.760
You can see electronic department is already there.

03:08.790 --> 03:12.990
Then when we start the next one is the electrical department.

03:14.850 --> 03:18.720
So electrical and we'll go ahead and update that.

03:20.070 --> 03:20.640
Okay.

03:20.640 --> 03:27.270
So we actually didn't change the student ID I want that first one to remain electronics.

03:27.930 --> 03:30.360
So electronics.

03:30.630 --> 03:31.200
All right.

03:31.230 --> 03:31.590
Go ahead.

03:31.590 --> 03:32.520
And that's that.

03:32.520 --> 03:40.740
So we have put that back to the tronics then change the ID to electrical so it can be some of the electrical

03:40.740 --> 03:41.460
department.

03:41.460 --> 03:44.040
So it will move to the second one right in here.

03:44.310 --> 03:51.630
And let me say the next one is going to be mechanical.

03:52.080 --> 03:53.580
So mechanical.

03:53.580 --> 03:58.760
And that is going to be for ID three I go ahead and run this and that is it.

03:58.760 --> 04:03.200
So the next one is going to be, let me say electronics as well.

04:05.480 --> 04:08.300
That is for ID four.

04:08.300 --> 04:09.710
And check this out.

04:09.740 --> 04:10.640
Electronics.

04:11.120 --> 04:12.950
And then the ID five.

04:13.640 --> 04:16.670
We go ahead and give that to be civil.

04:18.620 --> 04:20.450
So ID five civil.

04:21.350 --> 04:24.410
And let's update that civil is day.

04:24.410 --> 04:26.930
So we it remains two of them.

04:26.960 --> 04:32.630
Let's go ahead and give the next one to be statistics.

04:38.090 --> 04:38.840
Statistics.

04:38.840 --> 04:40.580
And that is for ID six.

04:40.580 --> 04:42.470
And let's go ahead and update that.

04:43.130 --> 04:49.220
And then let's go ahead and give the last one to be refresher.

04:52.400 --> 04:52.850
All right.

04:52.850 --> 04:55.310
So that is for ID seven.

04:57.600 --> 04:57.960
All right.

04:57.960 --> 04:59.460
So we have updated the table.

04:59.460 --> 05:01.380
And you can see now we have the apartments.

05:01.380 --> 05:04.500
So each of them have the department or drag this down.

05:05.100 --> 05:05.850
It can be.

05:05.880 --> 05:07.380
So we can be able to see that.

05:07.410 --> 05:09.150
Now we have been able to do that.

05:09.180 --> 05:17.760
Let's go ahead and uh check uh get students who enrolled between 19 or 2092.

05:17.790 --> 05:21.300
So if you want to check that let's go ahead and check that out.

05:21.300 --> 05:31.230
So I'll go ahead and say select Select all from the students table.

05:31.230 --> 05:34.140
And then we go ahead and give.

05:34.170 --> 05:35.010
We are cross.

05:36.930 --> 05:38.520
We are enrolled.

05:40.770 --> 05:41.670
Underscore dates.

05:41.670 --> 05:42.420
So we are enrolled.

05:42.450 --> 05:46.080
Dates is uh less than.

05:46.080 --> 05:49.350
So once people enroll below 2092.

05:49.380 --> 05:56.210
So semicolon at the end and then see 82.

05:57.620 --> 05:57.980
Right.

05:58.010 --> 06:01.010
For I just want to get this stuff right in here.

06:01.040 --> 06:04.340
I'll go right here and replace that.

06:04.340 --> 06:05.810
So this is the that I need.

06:05.840 --> 06:06.620
I want to be fast.

06:06.650 --> 06:08.630
Go ahead and refresh this and check it out.

06:08.930 --> 06:11.030
So we have this right here.

06:11.060 --> 06:13.280
We are selecting from all of them.

06:13.280 --> 06:15.410
So we are still populating this table here.

06:15.440 --> 06:18.110
Go ahead and remove this table because we're selecting here.

06:18.230 --> 06:19.790
If I run this and check it out.

06:19.790 --> 06:27.410
So you can see that we have only students who are who enrolled below the 2092 populated for us.

06:27.410 --> 06:29.360
So I was like what happened.

06:29.360 --> 06:37.160
So I have removed select from all the table below here and I can be able to see the student table that

06:37.160 --> 06:41.840
is there because this ID one, two, three, four and seven.

06:41.840 --> 06:45.410
So other ones are above 2092.

06:45.440 --> 06:51.740
Now let's go ahead and say from the above results let's find students in one of the departments.

06:51.740 --> 06:56.340
So if we want to do that let's go ahead and use the and operator.

06:56.370 --> 07:01.680
So I have to say end department.

07:07.080 --> 07:14.190
So end department is equal to let me say electronics.

07:19.980 --> 07:23.970
So go ahead under set electronics.

07:24.960 --> 07:26.550
And now let's check it out.

07:27.300 --> 07:32.790
So we have only pizza and Sara and both of them are electronics.

07:32.790 --> 07:33.840
You can see that.

07:33.870 --> 07:39.600
So in that way you can be able to use the and operator in the logical operator.

07:39.630 --> 07:43.560
So this is a way you can be able to use logical operator in MySQL.

07:43.590 --> 07:46.920
Now there is another operator known as the Or operator.

07:46.950 --> 07:49.650
So let me say I want to select everything.

07:49.680 --> 07:55.600
Let me go ahead and say I want to select We are the department.

07:55.630 --> 07:56.890
Go ahead and remove this.

07:58.810 --> 08:02.890
So select a ready department is equal to zero.

08:06.070 --> 08:10.660
All the department is going to be.

08:14.470 --> 08:15.130
Equal to.

08:15.130 --> 08:16.450
Let me choose another department.

08:16.570 --> 08:18.820
Let me see statistics.

08:22.930 --> 08:24.970
So it is not zero or statistics.

08:24.970 --> 08:29.140
And one of them can apply semicolon at the end and says run this.

08:29.140 --> 08:32.470
So we choose we see Mike and Queen.

08:32.470 --> 08:36.490
But of them civil or not statistics.

08:36.490 --> 08:42.220
And if you go ahead and use the and operator until we print it out because the inner one of them so

08:42.250 --> 08:45.160
and both of them are not in the same department.

08:45.160 --> 08:47.410
So if you go ahead and run this check it out.

08:47.680 --> 08:50.290
Nothing is being populated under the table.

08:50.320 --> 08:51.580
I hope you can see that.

08:51.580 --> 08:57.720
So now let's go ahead and find our students who are not in the electronics department.

08:57.720 --> 08:58.770
So these are not.

08:58.800 --> 08:59.550
Operator.

08:59.580 --> 09:02.430
Let me go ahead and show us how to use the Not operator to do this.

09:02.430 --> 09:08.670
So to find students one not in the department electronics, we go ahead and use the Not operator.

09:08.700 --> 09:14.490
We are not then department equal to.

09:17.880 --> 09:20.580
Electronics by a semicolon at the end.

09:20.610 --> 09:23.310
And then run this and check it out.

09:23.910 --> 09:31.530
So you can see we have two of them omitted the first ID and the default ID the first and the fourth

09:31.560 --> 09:34.800
ID are not there because both of them are electronic.

09:34.800 --> 09:38.670
So just populate the students who are not in electronics department.

09:38.670 --> 09:42.480
So that is a way you can be able to use the Not operator.

09:42.510 --> 09:48.000
You can also have an operator called and not and not is there.

09:48.030 --> 09:50.670
So if a guy has say maybe I don't want to populate.

09:50.670 --> 09:55.510
Students were also in electrical or mechanical or civil or statistics or literature.

09:55.540 --> 10:01.360
Our hand and say and not, then I will choose the departments.

10:01.450 --> 10:06.880
We say the department equal to.

10:06.910 --> 10:12.340
Then let's go to choose one department, let's say civil right now.

10:12.340 --> 10:16.630
So we don't want to show students who are both in electronics and civil.

10:16.630 --> 10:18.940
So let's go ahead and check it out.

10:19.000 --> 10:25.900
And you can see we don't have civil departments right in here because electronics and civil are no longer

10:25.900 --> 10:27.250
populated for us.

10:27.370 --> 10:32.350
I hope you can see that that is a part of the not logical operator.

10:33.130 --> 10:33.430
All right.

10:33.430 --> 10:35.740
So that is what we call the between operator.

10:35.770 --> 10:37.060
Let's go here and see.

10:37.150 --> 10:42.610
We want to select who are students who enrolled between this date and this date.

10:42.640 --> 10:46.420
And square here and remove this nut operator and check it out.

10:46.600 --> 10:51.730
Why not say I want our students who enroll is going to have a say?

10:51.730 --> 11:00.300
See in Rome that and you have to give the dates between.

11:02.460 --> 11:08.970
So you can see which is a key word between dates then and then the next date.

11:09.000 --> 11:10.200
Put a semicolon at the end.

11:10.200 --> 11:14.730
So go ahead and say ah one students were enrolled between.

11:18.000 --> 11:27.510
Uh 28 eight kind of prejudice and uh 2092 I had to face that and I had to run this and check it out.

11:28.380 --> 11:36.660
Now I can see we have the students who enrolled between 2088 and 2092, the the only students at the

11:36.690 --> 11:41.040
electronics day because it is not based on department anymore.

11:41.040 --> 11:42.660
So that is it.

11:42.690 --> 11:45.210
We can also go ahead and check out a GPS.

11:45.240 --> 11:50.460
Let's say people will have the GP between this and that guy and say GP because I've just been working

11:50.460 --> 11:51.420
with the department.

11:51.640 --> 11:53.290
So let's go ahead and remove this.

11:53.290 --> 12:02.800
And because the GP is an integer this guy will be 2.9 and the next one will be 3.83.8.

12:02.800 --> 12:06.820
So one people who have the GP between 2.9 and 3.8.

12:06.820 --> 12:08.950
And if we run this code we check it out.

12:09.220 --> 12:15.280
So we have only these people 2.9, 3.5, 3.7 and 3.8.

12:15.310 --> 12:16.900
They are within their range.

12:17.560 --> 12:17.920
All right.

12:17.920 --> 12:21.010
So we have another operator called the in operator.

12:21.040 --> 12:24.520
And this we can be able to find students within a particular set.

12:24.850 --> 12:28.720
All right let me go ahead and say we want to find students were within a particular set.

12:28.720 --> 12:34.270
So we can say we are a department where department.

12:34.300 --> 12:42.130
And then you give this set, then guide and say, I want people who are in statistics.

12:48.910 --> 12:52.650
Oh somewhere Laura in statistics.

12:52.680 --> 13:04.980
And the next one, I want people who are in civil and the next one is a mechanical.

13:07.500 --> 13:09.270
So these are the people I just want to populate.

13:09.300 --> 13:18.360
Then let's go ahead and print out these so you can see Barack, Mike and Quinn are in this category.

13:18.390 --> 13:23.640
And that is a way you can able to use the in operator in your MySQL.

13:23.670 --> 13:24.720
I hope that is cool.

13:24.720 --> 13:28.080
So we are now able to deal with the logical operators.

13:28.080 --> 13:29.040
Go ahead and practice that.

13:29.040 --> 13:29.910
Check it out more.

13:29.910 --> 13:34.290
And if you have any questions under these go ahead and use the question and answer section.

13:34.290 --> 13:36.750
And I'm going to get back to you as soon as possible.

13:36.780 --> 13:40.650
Thank you so much and I'm glad to see you in the next video lecture.
