1 00:00:00,180 --> 00:00:00,750 All right. 2 00:00:00,750 --> 00:00:07,380 So we're moving on to logical or which, as I just mentioned, is like the brother or sister to logical. 3 00:00:07,380 --> 00:00:14,850 And and if you've worked with any programming language you're most likely familiar with and and or logical 4 00:00:14,850 --> 00:00:21,450 and and logical or so logical or you can either write out as or or just like we could write a and for 5 00:00:21,450 --> 00:00:24,870 and or we can use these to pipe symbols. 6 00:00:24,870 --> 00:00:29,310 So these are not uppercase I's or L's or ones. 7 00:00:29,310 --> 00:00:35,130 They are the pipe character which is usually located above the right return or enter key. 8 00:00:35,130 --> 00:00:37,140 You have to hit shift most often to hit it. 9 00:00:38,490 --> 00:00:41,450 So it's two of them together, just like it was to Ampersand four. 10 00:00:41,460 --> 00:00:43,920 And it's just symbols. 11 00:00:44,190 --> 00:00:45,360 It's pretty standard. 12 00:00:45,370 --> 00:00:50,400 Rights are very standardized across all programming languages that I've worked in ampersand for and 13 00:00:50,400 --> 00:00:56,490 pipes for or but you can also use the phonetic or the spelled out version or so. 14 00:00:56,490 --> 00:00:59,700 Before we dive into exactly how it works, let's try something. 15 00:01:00,600 --> 00:01:02,310 So we had this in the last video. 16 00:01:02,340 --> 00:01:07,590 This selects all books written by Dave Eggers, released after the year 2010. 17 00:01:08,160 --> 00:01:12,960 But what if we just change the ampersand to the or pipes? 18 00:01:13,830 --> 00:01:15,480 What do you think will happen, first of all? 19 00:01:15,480 --> 00:01:19,260 So I'm just going to copy this so we don't have to type this all again. 20 00:01:21,700 --> 00:01:29,920 And just change the ampersand here to or and I'll make I'll hit return so it's clearer what's happening. 21 00:01:30,700 --> 00:01:35,470 So if we read this, if you just say the word or here it makes a bit more sense. 22 00:01:35,470 --> 00:01:42,430 Select title and author name and release here from books where author name is Eggers or released your 23 00:01:42,460 --> 00:01:43,930 is greater than 2010. 24 00:01:45,190 --> 00:01:55,180 So if we run it, what we'll get is all books written by Dave Eggers and all books where a release year 25 00:01:55,180 --> 00:01:56,590 is greater than 2010. 26 00:01:57,070 --> 00:02:02,890 So rather than both sides of this having to be true, just if either side is true, we'll get the data. 27 00:02:02,920 --> 00:02:07,230 So we get all the books by Eggers, including this one. 28 00:02:07,240 --> 00:02:11,110 Our heartbreaking work is Staggering Genius, which came before 2010. 29 00:02:11,560 --> 00:02:18,310 But then we move on to the second part, which MySQL selected all books that were released after 2010, 30 00:02:18,310 --> 00:02:20,110 regardless of the author name. 31 00:02:20,830 --> 00:02:25,840 So it's a way for us to specify two things, either of which we want to be true or both. 32 00:02:25,840 --> 00:02:32,200 So in the case of a hologram for the King, it is both written by Dave Eggers, and it was released 33 00:02:32,200 --> 00:02:33,550 after 2010. 34 00:02:34,590 --> 00:02:36,960 Or same thing with the circle here. 35 00:02:37,500 --> 00:02:41,910 But 10% happier, for instance, was only this part was true. 36 00:02:41,920 --> 00:02:48,060 Released year is greater than 2010 because author L name is Harris or Saunders in this case or Gaiman. 37 00:02:50,130 --> 00:02:55,320 So again, that symbol right there, I forgot I made this nice little slide with this animation that 38 00:02:55,320 --> 00:02:57,600 change a symbol is very, very important. 39 00:02:57,630 --> 00:02:59,910 It changes the meaning entirely from the statement. 40 00:03:00,570 --> 00:03:00,840 Okay. 41 00:03:01,530 --> 00:03:07,140 So if we have two conditions with an ampersand between them or three or any number of conditions with 42 00:03:07,140 --> 00:03:12,570 ampersand, it means that both sides must be true in order for the whole thing to be true, as we've 43 00:03:12,570 --> 00:03:13,440 seen already. 44 00:03:14,040 --> 00:03:20,900 However, with the OR operator, it means only one side must be true for the whole thing to be true, 45 00:03:20,910 --> 00:03:22,940 or both sides can be true as well. 46 00:03:22,950 --> 00:03:27,500 And I know that's a bit odd to talk about in this way without actual examples. 47 00:03:27,510 --> 00:03:31,860 So if we hop over again, I'm going to do the same thing I've been doing the last couple of videos. 48 00:03:31,860 --> 00:03:36,270 I'm going to type up a few example exercises and then we'll go over solutions. 49 00:03:36,540 --> 00:03:38,010 Okay, so I'm back here. 50 00:03:38,160 --> 00:03:44,670 I've got three, just three this time that I'll use logical or so try them out and then I'll be right 51 00:03:44,670 --> 00:03:47,730 back with a solution and I'm back already. 52 00:03:47,760 --> 00:03:49,950 Okay, so first one here. 53 00:03:50,310 --> 00:03:53,190 40 less than or equal to 100. 54 00:03:53,610 --> 00:03:55,050 Well, that part's true. 55 00:03:55,890 --> 00:03:57,060 40 is less than 100. 56 00:03:57,060 --> 00:03:59,040 So it doesn't matter what's over here. 57 00:03:59,040 --> 00:04:02,790 This whole thing is true because we only need one half to be true. 58 00:04:03,960 --> 00:04:11,730 It happens that negative two is not greater than zero, but that's irrelevant because the left side 59 00:04:11,730 --> 00:04:12,480 is true. 60 00:04:13,650 --> 00:04:17,360 Moving on to this one, ten greater than five, is that true? 61 00:04:17,370 --> 00:04:18,089 Yes. 62 00:04:19,190 --> 00:04:22,580 So it doesn't matter what's on the right side, but that happens to also be true. 63 00:04:22,580 --> 00:04:24,170 So the whole thing is true. 64 00:04:26,960 --> 00:04:32,150 So we get one and this last one, a bit of a curveball. 65 00:04:32,630 --> 00:04:35,240 Is the letter a equal to the number five? 66 00:04:35,270 --> 00:04:36,530 Well, that's not true. 67 00:04:37,250 --> 00:04:40,400 However, this side says 3000 is greater than 2000. 68 00:04:40,400 --> 00:04:41,220 That is true. 69 00:04:41,240 --> 00:04:42,680 So the whole thing is true. 70 00:04:45,370 --> 00:04:47,530 As you can see, we get one for true. 71 00:04:48,940 --> 00:04:54,400 Last thing before I forget just like with and we can chain or together as many times as we want so it 72 00:04:54,400 --> 00:04:56,080 doesn't have to be something like this. 73 00:04:56,230 --> 00:05:04,630 So if I go back to this example, select title, author l name or here from books where author name 74 00:05:04,630 --> 00:05:07,150 is Eggers or released year is greater than 2010. 75 00:05:07,150 --> 00:05:10,840 So let's try adding an OR here and I'll spell it out this time. 76 00:05:10,840 --> 00:05:17,560 And let's say not only do we care or do we want to select things written by Eggers or released year 77 00:05:17,560 --> 00:05:26,110 greater than 2010, we'll also add another or which is stock quantity is greater than 100 so books that 78 00:05:26,110 --> 00:05:27,850 we have a lot of stock in as well. 79 00:05:28,360 --> 00:05:33,940 And let's also print stock quantity just like that. 80 00:05:34,770 --> 00:05:38,320 Just copy this whole thing, paste it semicolon. 81 00:05:38,860 --> 00:05:48,250 And if we look see it makes a slight difference because we also get this David Foster Wallace story 82 00:05:48,250 --> 00:05:53,590 collection in here, which is written in 2004, which normally wouldn't make the cut with our previous 83 00:05:53,590 --> 00:05:58,690 version, but because we added stock quantity greater than 100, it's in here because stock quantity 84 00:05:58,690 --> 00:06:00,070 is greater than 172. 85 00:06:00,520 --> 00:06:05,530 So for some of these, for instance, a hologram for the King, all three parts are true. 86 00:06:05,560 --> 00:06:06,880 It's written by Eggers. 87 00:06:06,880 --> 00:06:11,170 It's released after 2010, and it has more than 100 copies in stock. 88 00:06:11,170 --> 00:06:16,420 But then, like for David Foster Wallace and Oblivion, only one part is true. 89 00:06:16,420 --> 00:06:17,200 The last part. 90 00:06:17,200 --> 00:06:22,630 So just goes to show you that only one component, even if we have three different conditions, only 91 00:06:22,630 --> 00:06:28,600 one part has to be true for the entire thing to be true and for it to be selected and spit back to us. 92 00:06:29,370 --> 00:06:29,920 Okay. 93 00:06:29,940 --> 00:06:30,900 So that's logical. 94 00:06:30,900 --> 00:06:37,140 Or one thing that I will point out that I know you're probably dying to get on with this video, but 95 00:06:37,140 --> 00:06:40,890 you can combine or and end and we'll see how to do that in a little bit.