1
00:00:00,180 --> 00:00:06,600
Next up, we're going to talk about logical or logical or is, I guess, a little bit like logical and

2
00:00:06,600 --> 00:00:14,220
only in the sense that we have a left in a right side that both will be evaluated and both can be different

3
00:00:14,220 --> 00:00:15,900
comparisons that we would make.

4
00:00:15,900 --> 00:00:18,000
But the end result is very different.

5
00:00:18,000 --> 00:00:23,860
So if we were to try this query here, select Star from Books where author last name is Eggers and release

6
00:00:23,870 --> 00:00:29,220
series Greater than 2010 and we've already done this, I'm just going to slim it down so that we only

7
00:00:29,220 --> 00:00:38,310
do title and author L name just so that we don't get that ugly formatting with my font size here.

8
00:00:38,520 --> 00:00:40,830
So we get those two books right.

9
00:00:41,100 --> 00:00:42,690
This is all from the last video.

10
00:00:42,720 --> 00:00:49,200
Both sides had to be true, last name had to be Eggers and release year had to be greater than 2010.

11
00:00:49,980 --> 00:00:55,770
But if I change that end to an OR with everything else exactly the same.

12
00:00:56,010 --> 00:00:57,960
So I'll just keep a record of both of them.

13
00:00:57,960 --> 00:00:59,760
But I'll change this to be in or.

14
00:01:00,730 --> 00:01:03,370
We'll get a very different result.

15
00:01:03,760 --> 00:01:09,310
So this result here contains all of the books that have an author name of Eggers.

16
00:01:09,310 --> 00:01:15,090
So there's those three or all of the books that have a release year greater than 2010.

17
00:01:15,100 --> 00:01:19,870
Now, we're actually not printing out the release here, so that is kind of screwing us up.

18
00:01:20,050 --> 00:01:24,790
Let's put that in here as well, because you can't tell for sure what's actually happening.

19
00:01:25,490 --> 00:01:26,660
Let's try that now.

20
00:01:27,980 --> 00:01:34,780
Now we can see all books by Eggers, but then also any book greater than or released after 2010.

21
00:01:34,790 --> 00:01:40,850
So we got 2016, 2014, 2017, and those are not written by Dave Eggers.

22
00:01:40,850 --> 00:01:44,660
So we're not satisfying this first comparison.

23
00:01:44,660 --> 00:01:51,920
But that's okay because we're using or the way that logical or works is that if we have a left and a

24
00:01:51,920 --> 00:01:59,420
right, only one of them has to be true in order for the whole thing to be considered true.

25
00:01:59,630 --> 00:02:05,980
In other words, in this example, if I'm MySQL going through all the rows and I check to see, okay,

26
00:02:05,990 --> 00:02:11,540
it's the author's last name Eggers on this row, if it is great, then we'll include that row.

27
00:02:11,540 --> 00:02:16,580
If it's not, well, what about this was it's released here greater than 2010.

28
00:02:16,580 --> 00:02:19,370
If that is true, then we'll also include the row.

29
00:02:19,640 --> 00:02:23,870
But again, if this was and instead both must be true.

30
00:02:24,290 --> 00:02:30,100
So we can use or in all sorts of ways, let me just demonstrate first how it behaves in the sort of

31
00:02:30,110 --> 00:02:34,520
vacuum of a logical operator, a very simple statement like this.

32
00:02:34,520 --> 00:02:36,440
So it's one less than five.

33
00:02:37,190 --> 00:02:38,930
We know that that's true.

34
00:02:38,960 --> 00:02:40,070
We get one.

35
00:02:40,700 --> 00:02:45,470
And if I do one, less than five or four is equal to five.

36
00:02:45,470 --> 00:02:52,460
Well, we know that this is not true, but we still get one because only one side of the or has to be

37
00:02:52,460 --> 00:02:53,060
true.

38
00:02:53,510 --> 00:02:58,880
If I change this to be an end now we get false because both sides have to be true.

39
00:02:58,880 --> 00:03:00,290
But this set is not.

40
00:03:00,710 --> 00:03:10,040
But if I had two false sides with my or like is one less than zero, that is false and the other side

41
00:03:10,040 --> 00:03:12,170
is false, the whole thing is false.

42
00:03:12,170 --> 00:03:14,390
So we still have to have one side be true.

43
00:03:15,080 --> 00:03:19,640
Here's a slide to summarize exactly what I just said with and both sides must be true.

44
00:03:19,640 --> 00:03:23,000
Both conditions with or only one side must be true.

45
00:03:23,120 --> 00:03:29,210
And then of course we could use or multiple times in the same way that we could have and multiple times

46
00:03:29,390 --> 00:03:34,580
like this example here and author last name is Eggers and title like novel.

47
00:03:34,580 --> 00:03:43,310
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

48
00:03:43,310 --> 00:03:49,310
and I want to find the books that are short or the books that are short story collections, because

49
00:03:49,310 --> 00:03:53,150
I don't want to start a long novel and then get off my flight and never finish it.

50
00:03:53,150 --> 00:03:57,740
But if it's a collection of short stories, I can read one or two stories and it's these small discrete

51
00:03:57,740 --> 00:04:01,610
units, or if it's a short book, then I can just read the whole book.

52
00:04:02,290 --> 00:04:11,380
So we'll do something like select the title, the page count, and just do that for now from books.

53
00:04:12,370 --> 00:04:17,709
And my first condition is going to be where pages, let's say, is less than 200.

54
00:04:18,279 --> 00:04:20,430
So that will give me all of the books that are short.

55
00:04:20,440 --> 00:04:22,330
We've already done this query, I'm pretty sure.

56
00:04:24,150 --> 00:04:25,470
Interpreter of Maladies.

57
00:04:25,470 --> 00:04:28,110
What we talk about when we talk about love and Cannery Row.

58
00:04:28,410 --> 00:04:34,800
But I also want to do the short story collections, and those are the ones that include stories in their

59
00:04:34,800 --> 00:04:35,400
title.

60
00:04:35,400 --> 00:04:43,200
So I'll do an or title like and then percent stories and percent afterwards.

61
00:04:43,320 --> 00:04:47,370
Go back to the wild card or the like video if you're not sure what the percents are.

62
00:04:47,370 --> 00:04:53,310
But I want to see if stories is somewhere in the middle at the beginning or the end of the title.

63
00:04:54,690 --> 00:04:56,650
And now we get all the short books.

64
00:04:56,670 --> 00:04:57,990
198.

65
00:04:58,650 --> 00:05:00,210
Cannery Row 181.

66
00:05:00,210 --> 00:05:05,490
But also long books like Where I'm Calling From Selected Stories and Oblivion Stories.

67
00:05:05,490 --> 00:05:07,020
But they are stories.

68
00:05:07,020 --> 00:05:12,240
They include stories in their title, so they pass the test that we set up.

69
00:05:12,240 --> 00:05:13,950
Only one side had to be true.

70
00:05:14,070 --> 00:05:18,330
So for oblivion, this book down here stories.

71
00:05:18,360 --> 00:05:19,560
The first part is not true.

72
00:05:19,560 --> 00:05:21,000
It was 329 pages.

73
00:05:21,000 --> 00:05:21,960
That's false.

74
00:05:21,960 --> 00:05:24,120
But this part was true.

75
00:05:24,120 --> 00:05:26,430
So the whole thing is considered true.

76
00:05:26,430 --> 00:05:29,790
And we get that book, that row included in our results.

77
00:05:30,120 --> 00:05:36,270
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

78
00:05:36,270 --> 00:05:37,980
in order for the whole thing to be true.

