So next step, we're moving on to the next subset of logical operators.
There's a group that fits together nicely, which you're probably familiar with just from middle school
or early school years.
And those are greater than greater than an equal to or greater than or equal to less than and less than
or equal to.
So for operators, very similar and pretty useful.
So this is the greater than operator in my SQL.
It's pretty standard.
The what is called the alligator bracket.
I don't know what to call this, honestly.
I just call it the greater than 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 released year is greater than the year 2000.
And typically we're working with numbers.
I'll talk about strings in a little bit, but typically we're working with numbers.
So an example, earlier today I was looking on Airbnb to book an Airbnb and they have a filter that
allows you to set a minimum price or a maximum price.
So if I wanted to, I could have gone in and said, I only want to book Airbnbs that have a price greater
than $50 a night or something to filter out the $20 a night 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.
If we hop over here, let's start by just selecting all titles and released here from books, and let's
just order by release.
We're just ordering it.
We'll let us see.
When we remove things, it will make it clearer rather than having them just be jumbled.
So we've got 1945 up to 2017.
Now, if I want to go ahead and do what I showed you, which is select all the books released in the
2000 or after the year 2000.
All I need to do is add in where released 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, which we'll get to in just a moment, but everything greater
than 2000 is.
So that gives us all of hoops, gives us all of these books from American Gods down to Lincoln in the
Bardo.
As 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 here rather than greater than, it's 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 100, including 100, 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.
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 99 greater than one.
What do you expect?
Well, go ahead and try it if you'd like.
I'll go and type it over here.
Select 99 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 MySQL 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 99 is greater than one.
That's true.
And 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 if that's confusing you, let's try something.
Let's change 99 greater than one to is 99 greater than five, six, seven.
I just lost it.
Here we go.
We know that that's false.
And you can see we get zero.
So the reason that I'm showing this to you is there's two reasons.
One is that it will help us going forward with some of the other things I'm 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.
But 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 where stock quantity is greater than or equal to 100.
You can almost think of it as MySQL, going through every stock quantity and plugging it in here and
trying it's 100 greater than or equal to 101.
Yes.
So keep that one is 23 greater than or equal to 100 zero.
No, false.
So get rid of that one and it does that going down the line.
That's kind of the humanized version, if you will, but it's evaluating to these numbers.
But those numbers are just 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, and I'd like for you to evaluate them yourselves.
Okay.
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 you'll need a semicolon.
But what's the result that you expect?
And there are a couple of straightforward 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 a thing on the screen that says you should do it.
And then in like 2 seconds, I'll be back.
All right, I'm back.
So first one, 100 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.
-15.
Greater than 15.
Is that true?
Well, no, I don't think so.
And we get zero.
All right.
Nine greater than negative ten.
That seems like it should be true.
And it is.
What about one greater than one?
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.
All right.
Now, these two.
String comparisons with greater than less than is notorious in all languages, for one being annoying
and confusing, and two 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 It comes before 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 SQL case, my SQL.
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.
So that brings us to our last one, which is a bit tricky, uppercase a greater than lowercase a and
if we run that.
With the semicolon, you'll see that it's false.
So uppercase A is not greater than lowercase a.
So then does that mean that it's lower?
Does uppercase a come before lowercase a?
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 A in my school's 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 l name equals.
If we do eggers like this and of course I 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 Edgar's like that with two uppercase G's, so the way that string comparisons work in my
SQL is quite odd.
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.