I will turn you back again to another video lecture in MySQL.
And in this video lecture, let's go ahead and look at logical operators in MySQL.
So in MySQL we have the logical operators.
And the operators are used to check more than one condition.
So it is very important we learn about it because you are always going to use it to query a table if
we're working in large organizations.
So first of all let me go ahead and add something to our table, the students table which is right before
us.
So I'll go ahead and add a department so it can be able to actually use that here.
So let's go ahead and see what a table and the table want to alter is a students table.
And then we'll go ahead and add another column to that.
So go ahead and add column.
And the column is going to be Department and is going to be involved at a time.
So varchar.
All right.
So I'll let it take just a 20 characters or 30 go.
So 20 is okay.
And I want to place that after the GP.
So we can have a clear demarcation between the first last name and the departments.
So after the GP we then go ahead and place that.
So this guy and say after GP and put a semicolon at the end.
Now let's go ahead and also show our table after we've done that and say select.
So select all from students.
Press semicolon at the end.
Go ahead and run this.
Let's check it out.
And now we have this null and null.
What it means is that we have to go ahead and update this room, because you can see we have added a
column right near the department column, but we don't have any, uh, values in there.
So let's go ahead and update that.
Go ahead and uh remove this.
So can we want to update that.
I'll go ahead and say update student uh table.
So update students and we go ahead and set our department.
So departments should be equal to let me say the first one electronics.
So electronics go ahead and uh say where we are close so we can be able to add that's where the student's
ID is equal to one.
I'll put a semicolon at the end.
And let's go ahead and run this and check it out.
So we have added electronics to pizza George.
You can see electronic department is already there.
Then when we start the next one is the electrical department.
So electrical and we'll go ahead and update that.
Okay.
So we actually didn't change the student ID I want that first one to remain electronics.
So electronics.
All right.
Go ahead.
And that's that.
So we have put that back to the tronics then change the ID to electrical so it can be some of the electrical
department.
So it will move to the second one right in here.
And let me say the next one is going to be mechanical.
So mechanical.
And that is going to be for ID three I go ahead and run this and that is it.
So the next one is going to be, let me say electronics as well.
That is for ID four.
And check this out.
Electronics.
And then the ID five.
We go ahead and give that to be civil.
So ID five civil.
And let's update that civil is day.
So we it remains two of them.
Let's go ahead and give the next one to be statistics.
Statistics.
And that is for ID six.
And let's go ahead and update that.
And then let's go ahead and give the last one to be refresher.
All right.
So that is for ID seven.
All right.
So we have updated the table.
And you can see now we have the apartments.
So each of them have the department or drag this down.
It can be.
So we can be able to see that.
Now we have been able to do that.
Let's go ahead and uh check uh get students who enrolled between 19 or 2092.
So if you want to check that let's go ahead and check that out.
So I'll go ahead and say select Select all from the students table.
And then we go ahead and give.
We are cross.
We are enrolled.
Underscore dates.
So we are enrolled.
Dates is uh less than.
So once people enroll below 2092.
So semicolon at the end and then see 82.
Right.
For I just want to get this stuff right in here.
I'll go right here and replace that.
So this is the that I need.
I want to be fast.
Go ahead and refresh this and check it out.
So we have this right here.
We are selecting from all of them.
So we are still populating this table here.
Go ahead and remove this table because we're selecting here.
If I run this and check it out.
So you can see that we have only students who are who enrolled below the 2092 populated for us.
So I was like what happened.
So I have removed select from all the table below here and I can be able to see the student table that
is there because this ID one, two, three, four and seven.
So other ones are above 2092.
Now let's go ahead and say from the above results let's find students in one of the departments.
So if we want to do that let's go ahead and use the and operator.
So I have to say end department.
So end department is equal to let me say electronics.
So go ahead under set electronics.
And now let's check it out.
So we have only pizza and Sara and both of them are electronics.
You can see that.
So in that way you can be able to use the and operator in the logical operator.
So this is a way you can be able to use logical operator in MySQL.
Now there is another operator known as the Or operator.
So let me say I want to select everything.
Let me go ahead and say I want to select We are the department.
Go ahead and remove this.
So select a ready department is equal to zero.
All the department is going to be.
Equal to.
Let me choose another department.
Let me see statistics.
So it is not zero or statistics.
And one of them can apply semicolon at the end and says run this.
So we choose we see Mike and Queen.
But of them civil or not statistics.
And if you go ahead and use the and operator until we print it out because the inner one of them so
and both of them are not in the same department.
So if you go ahead and run this check it out.
Nothing is being populated under the table.
I hope you can see that.
So now let's go ahead and find our students who are not in the electronics department.
So these are not.
Operator.
Let me go ahead and show us how to use the Not operator to do this.
So to find students one not in the department electronics, we go ahead and use the Not operator.
We are not then department equal to.
Electronics by a semicolon at the end.
And then run this and check it out.
So you can see we have two of them omitted the first ID and the default ID the first and the fourth
ID are not there because both of them are electronic.
So just populate the students who are not in electronics department.
So that is a way you can be able to use the Not operator.
You can also have an operator called and not and not is there.
So if a guy has say maybe I don't want to populate.
Students were also in electrical or mechanical or civil or statistics or literature.
Our hand and say and not, then I will choose the departments.
We say the department equal to.
Then let's go to choose one department, let's say civil right now.
So we don't want to show students who are both in electronics and civil.
So let's go ahead and check it out.
And you can see we don't have civil departments right in here because electronics and civil are no longer
populated for us.
I hope you can see that that is a part of the not logical operator.
All right.
So that is what we call the between operator.
Let's go here and see.
We want to select who are students who enrolled between this date and this date.
And square here and remove this nut operator and check it out.
Why not say I want our students who enroll is going to have a say?
See in Rome that and you have to give the dates between.
So you can see which is a key word between dates then and then the next date.
Put a semicolon at the end.
So go ahead and say ah one students were enrolled between.
Uh 28 eight kind of prejudice and uh 2092 I had to face that and I had to run this and check it out.
Now I can see we have the students who enrolled between 2088 and 2092, the the only students at the
electronics day because it is not based on department anymore.
So that is it.
We can also go ahead and check out a GPS.
Let's say people will have the GP between this and that guy and say GP because I've just been working
with the department.
So let's go ahead and remove this.
And because the GP is an integer this guy will be 2.9 and the next one will be 3.83.8.
So one people who have the GP between 2.9 and 3.8.
And if we run this code we check it out.
So we have only these people 2.9, 3.5, 3.7 and 3.8.
They are within their range.
All right.
So we have another operator called the in operator.
And this we can be able to find students within a particular set.
All right let me go ahead and say we want to find students were within a particular set.
So we can say we are a department where department.
And then you give this set, then guide and say, I want people who are in statistics.
Oh somewhere Laura in statistics.
And the next one, I want people who are in civil and the next one is a mechanical.
So these are the people I just want to populate.
Then let's go ahead and print out these so you can see Barack, Mike and Quinn are in this category.
And that is a way you can able to use the in operator in your MySQL.
I hope that is cool.
So we are now able to deal with the logical operators.
Go ahead and practice that.
Check it out more.
And if you have any questions under these go ahead and use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much and I'm glad to see you in the next video lecture.