Next up, we're going to talk about logical or logical or is, I guess, a little bit like logical and
only in the sense that we have a left in a right side that both will be evaluated and both can be different
comparisons that we would make.
But the end result is very different.
So if we were to try this query here, select Star from Books where author last name is Eggers and release
series Greater than 2010 and we've already done this, I'm just going to slim it down so that we only
do title and author L name just so that we don't get that ugly formatting with my font size here.
So we get those two books right.
This is all from the last video.
Both sides had to be true, last name had to be Eggers and release year had to be greater than 2010.
But if I change that end to an OR with everything else exactly the same.
So I'll just keep a record of both of them.
But I'll change this to be in or.
We'll get a very different result.
So this result here contains all of the books that have an author name of Eggers.
So there's those three or all of the books that have a release year greater than 2010.
Now, we're actually not printing out the release here, so that is kind of screwing us up.
Let's put that in here as well, because you can't tell for sure what's actually happening.
Let's try that now.
Now we can see all books by Eggers, but then also any book greater than or released after 2010.
So we got 2016, 2014, 2017, and those are not written by Dave Eggers.
So we're not satisfying this first comparison.
But that's okay because we're using or the way that logical or works is that if we have a left and a
right, only one of them has to be true in order for the whole thing to be considered true.
In other words, in this example, if I'm MySQL going through all the rows and I check to see, okay,
it's the author's last name Eggers on this row, if it is great, then we'll include that row.
If it's not, well, what about this was it's released here greater than 2010.
If that is true, then we'll also include the row.
But again, if this was and instead both must be true.
So we can use or in all sorts of ways, let me just demonstrate first how it behaves in the sort of
vacuum of a logical operator, a very simple statement like this.
So it's one less than five.
We know that that's true.
We get one.
And if I do one, less than five or four is equal to five.
Well, we know that this is not true, but we still get one because only one side of the or has to be
true.
If I change this to be an end now we get false because both sides have to be true.
But this set is not.
But if I had two false sides with my or like is one less than zero, that is false and the other side
is false, the whole thing is false.
So we still have to have one side be true.
Here's a slide to summarize exactly what I just said with and both sides must be true.
Both conditions with or only one side must be true.
And then of course we could use or multiple times in the same way that we could have and multiple times
like this example here and author last name is Eggers and title like novel.
I could do the same thing with or so why don't we do an example where I'm going on a very short flight
and I want to find the books that are short or the books that are short story collections, because
I don't want to start a long novel and then get off my flight and never finish it.
But if it's a collection of short stories, I can read one or two stories and it's these small discrete
units, or if it's a short book, then I can just read the whole book.
So we'll do something like select the title, the page count, and just do that for now from books.
And my first condition is going to be where pages, let's say, is less than 200.
So that will give me all of the books that are short.
We've already done this query, I'm pretty sure.
Interpreter of Maladies.
What we talk about when we talk about love and Cannery Row.
But I also want to do the short story collections, and those are the ones that include stories in their
title.
So I'll do an or title like and then percent stories and percent afterwards.
Go back to the wild card or the like video if you're not sure what the percents are.
But I want to see if stories is somewhere in the middle at the beginning or the end of the title.
And now we get all the short books.
198.
Cannery Row 181.
But also long books like Where I'm Calling From Selected Stories and Oblivion Stories.
But they are stories.
They include stories in their title, so they pass the test that we set up.
Only one side had to be true.
So for oblivion, this book down here stories.
The first part is not true.
It was 329 pages.
That's false.
But this part was true.
So the whole thing is considered true.
And we get that book, that row included in our results.
So that's how we can use or one side or the other, they can both be true or only one has to be true
in order for the whole thing to be true.