So next step we're moving on to the next subset of logical operators.
There is a group that fits together nicely which you're probably familiar with just from middle school
or early school years.
And those are the greater than greater than an equal to or sorry greater than or equal to less than
and less than or equal to.
So four operators are very similar and pretty useful.
So this is the greater than operator in my school it's pretty standard the way this is called Alligator
bracket.
I don't know what to call this honestly I just call it the grade with bracket.
It's pretty universal across programming and it allows us to do things like select all the books released
after a certain year so select all books where release is greater than the year 2000.
And typically we're working with numbers.
I'll talk about strings and a little bit but typically we're working with numbers.
So an example earlier today I was looking on every NBA to book an Air B and B and they have a filter
that allows you to set a minimum price or maximum price.
So if I wanted to I could have gone in and said I only want to book you know every piece that have a
price greater than $50 a night or something to filter out the $20 a night.
You know couches and some person's living room so that's powered.
Behind the scenes most likely by a greater than sign.
So now let's give it a shot on our own over here.
Let's start by just selecting all titles and released here from books.
And let's just order by release here just ordering it will let us see you know when we remove things.
It will make it clearer rather than having them just be jumbled.
OK.
So we've got 1945 up to 2017 if I want to go ahead and do what I showed you which is select all the
books released in the 2000s or after the year 2000.
All I need to do is add in where release to year is greater than 2000 just like that.
And if we look we lost everything.
From here on back.
So from Cannery Row to The Amazing Adventures of Kavalier and Clay.
Important to note that 2000 is not included.
We'll get to in just a moment.
But everything greater than 2000 is.
So that gives us all loops it's just all these books for American Gods down to Lincoln and the Bardo
you can see here we go.
So that brings us to greater than or equal to which works exactly the same way except you add in this
equal sign afterwards which makes it rather than greater than it makes it greater than or equal to which
means that it's inclusive.
So if I just change that and do where released year rather than greater than is greater than or equal
to 2000 now it includes the year 2000.
Let's do one more quick example.
Let's do a select title and stock quantity from books and let's say that we're going to do a sale because
we have some excess stock in some of our books.
Any book that we have more than one hundred including one hundred Let's say so 100 or more copies in
stock.
We want to select and we're going to discount them.
So how do we select those.
Well it's pretty straightforward.
We're just going to select title and stock quantity from books where stock quantity is greater than
or equal to 100.
And there we go.
These are the books that we're going to discount.
All right.
OK.
So there's one other small tangent I want to talk about.
It's a bit of a diversion away from the tables and books that we've been working with.
This has nothing to do with any particular data.
But if you try running something like this select ninety nine greater than one what do you expect.
Well go ahead and try to if you'd like to go and type it over here.
Select ninety nine greater than one if we hit Enter we get the number one back.
All right.
So if you're familiar with other programming languages you've probably come across boolean values.
True or false values.
And that's what my ask who is replicating here.
So the way that it works in Boolean logic is it actually works with the numbers zeros and one.
So we know that ninety nine is greater than 1 that's true.
So we get one which is equivalent to true.
Basically this evaluates to one which you can think of as evaluating to true.
So if it's if that's confusing you.
Let's try something.
Let's change nine.
Greater than 1 2 is ninety nine greater than 5 6 7.
I just lost it.
Here we go.
We know that that's false.
And you can see if we get zero.
So the reason I'm showing this to you.
Well there's two reasons.
One is that it will help us going forward with some of the other things are going to show you when we
can start changing things together.
You'll be able to evaluate them and kind of do some exercises on your own first.
The other thing and the more important reason is that this is what's happening behind the scenes.
When we have something like this right here we're stuck.
Quantity is greater than or equal to 100.
You can almost think of it as my as you're going through every stock quantity and playing it in here
and trying OK it's 100 greater than or equal to 100.
One.
Yes.
OK.
So keep that one is 23 greater than or equal to 100.
0 No false.
So get rid of that one and if it does that you know going down the line that's kind of the humanised
version if you will but it's evaluating to these numbers but those numbers are just you know bits and
memory.
But the concept is the same.
So if you'd like let's wrap this up with just a really simple exercise.
I'm going to type up a few things for you to evaluate them yourselves.
OK.
So I typed up a couple of examples here and I'd like for you to just either mentally try these or actually
try them yourselves.
And remember you'll need to actually run select and don't need a semi-colon.
But what's the result that you expect.
And there are a couple of straight forward ones.
And then I threw in two string ones at the end basically to give myself a talking point at the end.
I want to talk about why this happens and if you should care so go ahead I'll throw up the thing on
the screen that says you should do it.
And then in like two seconds I'll be back.
All right I'm back.
So first one.
One hundred.
Greater than five.
Is that true.
Well yes I believe that to be true.
Just to double check it gives us one.
That means we're in the clear negative 15 greater than 15.
Is that true.
Well no I don't think so.
And we get zero.
All right.
Nine greater than negative 10.
That seems like it should be true and it is what about 1 greater than 1.
Well I don't think one is greater than one.
So it's false.
However if there was the equal sign of course it would be true.
Now these two string comparisons with greater than less and is notorious in all languages for one being
annoying and confusing and to differing radically between languages.
So the advice that I would give to anyone is to just avoid ever having to do anything like this.
There are ways around it but I just wanted to show you what happens.
So what do you think is the lowercase a culture for B.
So is it greater than or less than B.
And in some languages it is greater than in others it's less than in my case my ass.
Q Well if we hit Enter we can see that a is not greater than B meaning that it's less than B although
technically that statement is logically wrong because it could be equal to B.
But as you can see if I add that equal sign it's still false.
So we know definitely a is less than B.
Ok so that brings us to our last one which is a bit tricky upper case a greater than lower case.
And if we run with a semi-colon you'll see that it's false.
So uppercase case is not greater than lowercase J.
So then does that mean that it's lower as upper case a come before lower case.
And the answer is actually if we change this just slightly to be greater than or equal to.
You'll see now it's true.
So that tells us uppercase a is equivalent to lowercase say in my eyes.
And we've seen that before.
When we do something like Well let me just type it again.
Select author L. name where author name equals Buju Eggers like this.
And of course they add in the all important table name from books.
So if I do this.
And let's also do title just to make it easier to see what's going on.
It matches just fine.
But I can also do this with lowercase e and it works just the same.
Or I can do Aggers like that with two uppercase G's.
So the way that string comparisons work in my school is quite odd in and if you're familiar with other
languages it's very different from pretty much every language I've worked with.
So just something worth noting that case doesn't actually matter.