1 00:00:00,120 --> 00:00:03,620 So next step, we're moving on to the next subset of logical operators. 2 00:00:03,630 --> 00:00:09,270 There's a group that fits together nicely, which you're probably familiar with just from middle school 3 00:00:09,270 --> 00:00:11,160 or early school years. 4 00:00:11,280 --> 00:00:18,030 And those are greater than greater than an equal to or greater than or equal to less than and less than 5 00:00:18,030 --> 00:00:18,630 or equal to. 6 00:00:18,660 --> 00:00:22,080 So for operators, very similar and pretty useful. 7 00:00:22,320 --> 00:00:25,950 So this is the greater than operator in my SQL. 8 00:00:25,980 --> 00:00:27,220 It's pretty standard. 9 00:00:27,240 --> 00:00:30,270 The what is called the alligator bracket. 10 00:00:30,570 --> 00:00:32,310 I don't know what to call this, honestly. 11 00:00:32,580 --> 00:00:34,060 I just call it the greater than bracket. 12 00:00:34,080 --> 00:00:40,920 It's pretty universal across programming, and it allows us to do things like select all the books released 13 00:00:40,920 --> 00:00:42,450 after a certain year. 14 00:00:42,450 --> 00:00:47,880 So select all books where released year is greater than the year 2000. 15 00:00:48,600 --> 00:00:50,490 And typically we're working with numbers. 16 00:00:50,490 --> 00:00:53,430 I'll talk about strings in a little bit, but typically we're working with numbers. 17 00:00:53,430 --> 00:01:02,220 So an example, earlier today I was looking on Airbnb to book an Airbnb and they have a filter that 18 00:01:02,220 --> 00:01:06,030 allows you to set a minimum price or a maximum price. 19 00:01:06,030 --> 00:01:12,900 So if I wanted to, I could have gone in and said, I only want to book Airbnbs that have a price greater 20 00:01:12,900 --> 00:01:20,430 than $50 a night or something to filter out the $20 a night couches and some person's living room. 21 00:01:20,520 --> 00:01:24,330 So that's powered behind the scenes, most likely by a greater than sign. 22 00:01:24,330 --> 00:01:26,370 So now let's give it a shot on our own. 23 00:01:26,820 --> 00:01:36,120 If we hop over here, let's start by just selecting all titles and released here from books, and let's 24 00:01:36,120 --> 00:01:37,740 just order by release. 25 00:01:37,740 --> 00:01:39,480 We're just ordering it. 26 00:01:39,510 --> 00:01:40,680 We'll let us see. 27 00:01:41,580 --> 00:01:45,810 When we remove things, it will make it clearer rather than having them just be jumbled. 28 00:01:46,860 --> 00:01:49,890 So we've got 1945 up to 2017. 29 00:01:49,890 --> 00:01:54,360 Now, if I want to go ahead and do what I showed you, which is select all the books released in the 30 00:01:54,360 --> 00:01:56,700 2000 or after the year 2000. 31 00:01:57,900 --> 00:02:07,740 All I need to do is add in where released year is greater than 2000 just like that. 32 00:02:10,250 --> 00:02:12,620 And if we look, we lost everything. 33 00:02:14,720 --> 00:02:16,410 From here on back. 34 00:02:16,430 --> 00:02:19,640 So from Cannery Row to The Amazing Adventures of Kavalier and Clay. 35 00:02:19,760 --> 00:02:25,550 Important to note that 2000 is not included, which we'll get to in just a moment, but everything greater 36 00:02:25,550 --> 00:02:26,900 than 2000 is. 37 00:02:26,930 --> 00:02:32,870 So that gives us all of hoops, gives us all of these books from American Gods down to Lincoln in the 38 00:02:32,870 --> 00:02:33,410 Bardo. 39 00:02:34,630 --> 00:02:35,500 As you can see. 40 00:02:35,620 --> 00:02:36,310 Here we go. 41 00:02:37,240 --> 00:02:43,210 So that brings us to greater than or equal to, which works exactly the same way, except you add in 42 00:02:43,210 --> 00:02:47,620 this equal sign afterwards, which makes it rather than greater than it makes it greater than or equal 43 00:02:47,620 --> 00:02:49,930 to, which means that it's inclusive. 44 00:02:51,250 --> 00:02:57,010 So if I just change that and do where released here rather than greater than, it's greater than or 45 00:02:57,010 --> 00:02:58,360 equal to 2000. 46 00:02:59,410 --> 00:03:01,570 Now it includes the year 2000. 47 00:03:02,770 --> 00:03:04,450 Let's do one more quick example. 48 00:03:05,350 --> 00:03:10,090 Let's do a select title and stock quantity from books. 49 00:03:10,870 --> 00:03:16,810 And let's say that we're going to do a sale because we have some excess stock in some of our books. 50 00:03:16,810 --> 00:03:21,730 Any book that we have more than 100, including 100, let's say. 51 00:03:21,730 --> 00:03:23,980 So 100 or more copies in stock. 52 00:03:24,280 --> 00:03:27,040 We want to select and we're going to discount them. 53 00:03:27,370 --> 00:03:28,870 So how do we select those? 54 00:03:28,930 --> 00:03:30,230 Well, it's pretty straightforward. 55 00:03:30,250 --> 00:03:37,180 We're just going to select title and stock quantity from books where stock quantity is greater than 56 00:03:37,510 --> 00:03:38,980 or equal to 100. 57 00:03:40,840 --> 00:03:41,800 And there we go. 58 00:03:42,190 --> 00:03:44,440 These are the books that we're going to discount. 59 00:03:45,400 --> 00:03:45,970 All right. 60 00:03:46,870 --> 00:03:49,690 So there's one other small tangent I want to talk about. 61 00:03:49,780 --> 00:03:54,040 It's a bit of a diversion away from the tables and books that we've been working with. 62 00:03:54,070 --> 00:03:57,310 This has nothing to do with any particular data. 63 00:03:57,880 --> 00:04:03,280 But if you try running something like this, select 99 greater than one. 64 00:04:04,100 --> 00:04:05,210 What do you expect? 65 00:04:06,680 --> 00:04:08,450 Well, go ahead and try it if you'd like. 66 00:04:08,480 --> 00:04:10,220 I'll go and type it over here. 67 00:04:10,490 --> 00:04:13,580 Select 99 greater than one. 68 00:04:13,940 --> 00:04:17,750 If we hit enter, we get the number one back. 69 00:04:17,990 --> 00:04:23,030 All right, so if you're familiar with other programming languages, you've probably come across Boolean 70 00:04:23,030 --> 00:04:23,490 values. 71 00:04:23,510 --> 00:04:25,070 True or false values. 72 00:04:25,070 --> 00:04:27,880 And that's what MySQL is replicating here. 73 00:04:27,890 --> 00:04:32,960 So the way that it works in Boolean logic is it actually works with the numbers, zeros and one. 74 00:04:34,230 --> 00:04:38,100 So we know that 99 is greater than one. 75 00:04:38,430 --> 00:04:39,510 That's true. 76 00:04:40,450 --> 00:04:44,310 And so we get one, which is equivalent to true. 77 00:04:44,340 --> 00:04:48,310 Basically, this evaluates to one which you can think of as evaluating to true. 78 00:04:48,330 --> 00:04:51,390 So if if that's confusing you, let's try something. 79 00:04:51,780 --> 00:04:59,280 Let's change 99 greater than one to is 99 greater than five, six, seven. 80 00:04:59,970 --> 00:05:00,750 I just lost it. 81 00:05:00,780 --> 00:05:01,380 Here we go. 82 00:05:01,560 --> 00:05:03,060 We know that that's false. 83 00:05:03,660 --> 00:05:05,490 And you can see we get zero. 84 00:05:06,720 --> 00:05:09,120 So the reason that I'm showing this to you is there's two reasons. 85 00:05:09,120 --> 00:05:13,620 One is that it will help us going forward with some of the other things I'm going to show you. 86 00:05:13,710 --> 00:05:18,990 When we can start changing things together, you'll be able to evaluate them and kind of do some exercises 87 00:05:18,990 --> 00:05:20,070 on your own first. 88 00:05:20,640 --> 00:05:25,620 But the other thing and the more important reason is that this is what's happening behind the scenes. 89 00:05:25,620 --> 00:05:31,540 When we have something like this right here where stock quantity is greater than or equal to 100. 90 00:05:31,560 --> 00:05:38,280 You can almost think of it as MySQL, going through every stock quantity and plugging it in here and 91 00:05:38,280 --> 00:05:42,350 trying it's 100 greater than or equal to 101. 92 00:05:42,360 --> 00:05:43,050 Yes. 93 00:05:43,410 --> 00:05:47,850 So keep that one is 23 greater than or equal to 100 zero. 94 00:05:47,850 --> 00:05:48,800 No, false. 95 00:05:48,810 --> 00:05:52,830 So get rid of that one and it does that going down the line. 96 00:05:53,130 --> 00:05:58,530 That's kind of the humanized version, if you will, but it's evaluating to these numbers. 97 00:05:58,530 --> 00:06:03,720 But those numbers are just bits and memory, but the concept is the same. 98 00:06:04,200 --> 00:06:08,870 So if you'd like, let's wrap this up with just a really simple exercise. 99 00:06:08,880 --> 00:06:12,630 I'm going to type up a few things, and I'd like for you to evaluate them yourselves. 100 00:06:14,810 --> 00:06:15,070 Okay. 101 00:06:15,170 --> 00:06:21,710 So I typed up a couple of examples here, and I'd like for you to just either mentally try these or 102 00:06:21,710 --> 00:06:23,030 actually try them yourselves. 103 00:06:23,030 --> 00:06:26,810 And remember, you'll need to actually run, select and you'll need a semicolon. 104 00:06:26,810 --> 00:06:29,720 But what's the result that you expect? 105 00:06:30,050 --> 00:06:36,260 And there are a couple of straightforward ones, and then I threw in two string ones at the end, basically 106 00:06:36,260 --> 00:06:37,400 to give myself a talking point. 107 00:06:37,400 --> 00:06:41,540 At the end, I want to talk about why this happens and if you should care. 108 00:06:41,810 --> 00:06:43,040 So go ahead. 109 00:06:43,040 --> 00:06:45,260 I'll throw up a thing on the screen that says you should do it. 110 00:06:45,770 --> 00:06:47,840 And then in like 2 seconds, I'll be back. 111 00:06:49,570 --> 00:06:50,710 All right, I'm back. 112 00:06:51,040 --> 00:06:54,730 So first one, 100 greater than five. 113 00:06:54,760 --> 00:06:55,600 Is that true? 114 00:06:55,720 --> 00:06:58,300 Well, yes, I believe that to be true. 115 00:06:58,330 --> 00:07:01,770 Just to double check, it gives us one. 116 00:07:01,780 --> 00:07:02,920 That means we're in the clear. 117 00:07:03,640 --> 00:07:04,950 -15. 118 00:07:04,960 --> 00:07:06,050 Greater than 15. 119 00:07:06,070 --> 00:07:07,150 Is that true? 120 00:07:07,240 --> 00:07:10,810 Well, no, I don't think so. 121 00:07:11,590 --> 00:07:12,610 And we get zero. 122 00:07:12,910 --> 00:07:13,510 All right. 123 00:07:13,990 --> 00:07:16,300 Nine greater than negative ten. 124 00:07:17,590 --> 00:07:19,290 That seems like it should be true. 125 00:07:19,300 --> 00:07:20,260 And it is. 126 00:07:20,800 --> 00:07:23,320 What about one greater than one? 127 00:07:25,400 --> 00:07:28,310 Well, I don't think one is greater than one, so it's false. 128 00:07:28,340 --> 00:07:31,700 However, if there was the equal sign, of course it would be true. 129 00:07:32,180 --> 00:07:32,750 All right. 130 00:07:33,020 --> 00:07:34,340 Now, these two. 131 00:07:35,160 --> 00:07:42,600 String comparisons with greater than less than is notorious in all languages, for one being annoying 132 00:07:42,600 --> 00:07:46,170 and confusing, and two differing radically between languages. 133 00:07:46,170 --> 00:07:51,870 So the advice that I would give to anyone is to just avoid ever having to do anything like this. 134 00:07:51,870 --> 00:07:55,190 There are ways around it, but I just wanted to show you what happens. 135 00:07:55,200 --> 00:08:01,650 So what do you think is the lowercase A It comes before B, so is it greater than or less than B? 136 00:08:02,430 --> 00:08:04,410 And in some languages it is greater than. 137 00:08:04,410 --> 00:08:09,030 In others it's less than in my SQL case, my SQL. 138 00:08:10,080 --> 00:08:16,410 If we hit enter, we can see that A is not greater than B, meaning that it's less than B. 139 00:08:17,370 --> 00:08:22,380 Although technically that statement is logically wrong because it could be equal to B. 140 00:08:22,380 --> 00:08:26,280 But as you can see, if I add that equal sign, it's still false. 141 00:08:26,430 --> 00:08:29,490 So we know definitely A is less than B. 142 00:08:30,480 --> 00:08:37,409 So that brings us to our last one, which is a bit tricky, uppercase a greater than lowercase a and 143 00:08:37,409 --> 00:08:38,429 if we run that. 144 00:08:40,600 --> 00:08:42,870 With the semicolon, you'll see that it's false. 145 00:08:42,880 --> 00:08:46,060 So uppercase A is not greater than lowercase a. 146 00:08:46,120 --> 00:08:49,930 So then does that mean that it's lower? 147 00:08:50,680 --> 00:08:53,890 Does uppercase a come before lowercase a? 148 00:08:54,010 --> 00:09:00,160 And the answer is actually, if we change this just slightly to be greater than or equal to, you'll 149 00:09:00,160 --> 00:09:00,340 see. 150 00:09:00,340 --> 00:09:01,360 Now it's true. 151 00:09:01,540 --> 00:09:09,580 So that tells us uppercase a is equivalent to lowercase A in my school's eyes and we've seen that before. 152 00:09:09,580 --> 00:09:13,630 When we do something like, well, let me just type it again. 153 00:09:13,630 --> 00:09:23,590 Select author l name where author l name equals. 154 00:09:24,550 --> 00:09:31,960 If we do eggers like this and of course I add in the all important table name from books. 155 00:09:34,090 --> 00:09:41,890 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 156 00:09:41,890 --> 00:09:42,520 fine. 157 00:09:43,120 --> 00:09:46,780 But I can also do this with lowercase e and it works just the same. 158 00:09:46,780 --> 00:09:53,470 Or I can do Edgar's like that with two uppercase G's, so the way that string comparisons work in my 159 00:09:53,500 --> 00:09:54,850 SQL is quite odd. 160 00:09:54,970 --> 00:09:59,200 And if you're familiar with other languages, it's very different from pretty much every language I've 161 00:09:59,200 --> 00:09:59,860 worked with. 162 00:10:00,280 --> 00:10:03,700 So just something worth noting that case doesn't actually matter.