WEBVTT

00:00.090 --> 00:03.680
So next step we're moving on to the next subset of logical operators.

00:03.690 --> 00:09.240
There is a group that fits together nicely which you're probably familiar with just from middle school

00:09.240 --> 00:11.110
or early school years.

00:11.460 --> 00:17.160
And those are the greater than greater than an equal to or sorry greater than or equal to less than

00:17.400 --> 00:18.630
and less than or equal to.

00:18.780 --> 00:22.160
So four operators are very similar and pretty useful.

00:22.470 --> 00:29.700
So this is the greater than operator in my school it's pretty standard the way this is called Alligator

00:29.850 --> 00:30.550
bracket.

00:30.690 --> 00:34.120
I don't know what to call this honestly I just call it the grade with bracket.

00:34.140 --> 00:40.860
It's pretty universal across programming and it allows us to do things like select all the books released

00:40.950 --> 00:48.010
after a certain year so select all books where release is greater than the year 2000.

00:48.720 --> 00:50.460
And typically we're working with numbers.

00:50.460 --> 00:53.380
I'll talk about strings and a little bit but typically we're working with numbers.

00:53.490 --> 01:02.070
So an example earlier today I was looking on every NBA to book an Air B and B and they have a filter

01:02.070 --> 01:06.180
that allows you to set a minimum price or maximum price.

01:06.180 --> 01:11.940
So if I wanted to I could have gone in and said I only want to book you know every piece that have a

01:11.940 --> 01:17.130
price greater than $50 a night or something to filter out the $20 a night.

01:17.430 --> 01:21.590
You know couches and some person's living room so that's powered.

01:21.600 --> 01:24.300
Behind the scenes most likely by a greater than sign.

01:24.420 --> 01:28.480
So now let's give it a shot on our own over here.

01:28.860 --> 01:35.320
Let's start by just selecting all titles and released here from books.

01:35.760 --> 01:43.060
And let's just order by release here just ordering it will let us see you know when we remove things.

01:43.110 --> 01:45.950
It will make it clearer rather than having them just be jumbled.

01:46.430 --> 01:46.800
OK.

01:46.920 --> 01:52.980
So we've got 1945 up to 2017 if I want to go ahead and do what I showed you which is select all the

01:52.980 --> 01:57.580
books released in the 2000s or after the year 2000.

01:57.790 --> 02:10.190
All I need to do is add in where release to year is greater than 2000 just like that.

02:10.320 --> 02:12.750
And if we look we lost everything.

02:14.660 --> 02:16.520
From here on back.

02:16.520 --> 02:19.920
So from Cannery Row to The Amazing Adventures of Kavalier and Clay.

02:19.940 --> 02:23.420
Important to note that 2000 is not included.

02:23.480 --> 02:24.610
We'll get to in just a moment.

02:24.800 --> 02:26.950
But everything greater than 2000 is.

02:26.990 --> 02:33.170
So that gives us all loops it's just all these books for American Gods down to Lincoln and the Bardo

02:34.710 --> 02:36.670
you can see here we go.

02:37.230 --> 02:43.360
So that brings us to greater than or equal to which works exactly the same way except you add in this

02:43.390 --> 02:48.430
equal sign afterwards which makes it rather than greater than it makes it greater than or equal to which

02:48.430 --> 02:50.210
means that it's inclusive.

02:51.340 --> 02:57.220
So if I just change that and do where released year rather than greater than is greater than or equal

02:57.220 --> 03:02.760
to 2000 now it includes the year 2000.

03:02.770 --> 03:05.010
Let's do one more quick example.

03:05.350 --> 03:13.780
Let's do a select title and stock quantity from books and let's say that we're going to do a sale because

03:13.990 --> 03:16.980
we have some excess stock in some of our books.

03:17.060 --> 03:23.380
Any book that we have more than one hundred including one hundred Let's say so 100 or more copies in

03:23.380 --> 03:24.230
stock.

03:24.460 --> 03:27.150
We want to select and we're going to discount them.

03:27.520 --> 03:28.800
So how do we select those.

03:29.020 --> 03:30.430
Well it's pretty straightforward.

03:30.430 --> 03:36.940
We're just going to select title and stock quantity from books where stock quantity is greater than

03:37.570 --> 03:40.430
or equal to 100.

03:40.960 --> 03:42.100
And there we go.

03:42.190 --> 03:45.290
These are the books that we're going to discount.

03:45.420 --> 03:46.170
All right.

03:46.500 --> 03:46.850
OK.

03:46.860 --> 03:49.670
So there's one other small tangent I want to talk about.

03:49.950 --> 03:54.220
It's a bit of a diversion away from the tables and books that we've been working with.

03:54.240 --> 03:57.350
This has nothing to do with any particular data.

03:57.960 --> 04:05.360
But if you try running something like this select ninety nine greater than one what do you expect.

04:06.790 --> 04:10.310
Well go ahead and try to if you'd like to go and type it over here.

04:10.690 --> 04:18.050
Select ninety nine greater than one if we hit Enter we get the number one back.

04:18.070 --> 04:18.370
All right.

04:18.370 --> 04:23.490
So if you're familiar with other programming languages you've probably come across boolean values.

04:23.500 --> 04:25.020
True or false values.

04:25.270 --> 04:27.850
And that's what my ask who is replicating here.

04:28.000 --> 04:34.250
So the way that it works in Boolean logic is it actually works with the numbers zeros and one.

04:34.320 --> 04:39.990
So we know that ninety nine is greater than 1 that's true.

04:40.480 --> 04:44.290
So we get one which is equivalent to true.

04:44.400 --> 04:48.430
Basically this evaluates to one which you can think of as evaluating to true.

04:48.450 --> 04:50.280
So if it's if that's confusing you.

04:50.310 --> 04:51.410
Let's try something.

04:51.840 --> 04:53.380
Let's change nine.

04:53.610 --> 04:59.510
Greater than 1 2 is ninety nine greater than 5 6 7.

05:00.000 --> 05:00.800
I just lost it.

05:00.810 --> 05:01.430
Here we go.

05:01.710 --> 05:03.380
We know that that's false.

05:03.660 --> 05:06.030
And you can see if we get zero.

05:06.810 --> 05:08.290
So the reason I'm showing this to you.

05:08.330 --> 05:09.120
Well there's two reasons.

05:09.120 --> 05:14.010
One is that it will help us going forward with some of the other things are going to show you when we

05:14.010 --> 05:15.430
can start changing things together.

05:15.450 --> 05:20.640
You'll be able to evaluate them and kind of do some exercises on your own first.

05:20.760 --> 05:25.590
The other thing and the more important reason is that this is what's happening behind the scenes.

05:25.830 --> 05:29.370
When we have something like this right here we're stuck.

05:29.370 --> 05:31.730
Quantity is greater than or equal to 100.

05:31.740 --> 05:37.110
You can almost think of it as my as you're going through every stock quantity and playing it in here

05:38.130 --> 05:41.530
and trying OK it's 100 greater than or equal to 100.

05:41.790 --> 05:42.360
One.

05:42.480 --> 05:43.010
Yes.

05:43.080 --> 05:43.410
OK.

05:43.410 --> 05:47.170
So keep that one is 23 greater than or equal to 100.

05:47.260 --> 05:48.890
0 No false.

05:48.900 --> 05:54.630
So get rid of that one and if it does that you know going down the line that's kind of the humanised

05:54.630 --> 06:00.390
version if you will but it's evaluating to these numbers but those numbers are just you know bits and

06:00.390 --> 06:01.690
memory.

06:01.950 --> 06:03.870
But the concept is the same.

06:04.350 --> 06:08.770
So if you'd like let's wrap this up with just a really simple exercise.

06:09.000 --> 06:12.650
I'm going to type up a few things for you to evaluate them yourselves.

06:14.760 --> 06:15.180
OK.

06:15.200 --> 06:22.070
So I typed up a couple of examples here and I'd like for you to just either mentally try these or actually

06:22.070 --> 06:22.950
try them yourselves.

06:23.150 --> 06:27.010
And remember you'll need to actually run select and don't need a semi-colon.

06:27.040 --> 06:29.780
But what's the result that you expect.

06:30.110 --> 06:32.580
And there are a couple of straight forward ones.

06:32.660 --> 06:37.700
And then I threw in two string ones at the end basically to give myself a talking point at the end.

06:37.700 --> 06:43.760
I want to talk about why this happens and if you should care so go ahead I'll throw up the thing on

06:43.760 --> 06:45.640
the screen that says you should do it.

06:45.890 --> 06:48.150
And then in like two seconds I'll be back.

06:49.610 --> 06:51.300
All right I'm back.

06:51.300 --> 06:52.640
So first one.

06:52.690 --> 06:53.730
One hundred.

06:53.730 --> 06:54.710
Greater than five.

06:54.720 --> 06:55.640
Is that true.

06:55.890 --> 06:58.390
Well yes I believe that to be true.

06:58.470 --> 07:01.740
Just to double check it gives us one.

07:01.830 --> 07:06.050
That means we're in the clear negative 15 greater than 15.

07:06.050 --> 07:07.120
Is that true.

07:07.400 --> 07:11.440
Well no I don't think so.

07:11.640 --> 07:12.570
And we get zero.

07:12.980 --> 07:14.150
All right.

07:14.150 --> 07:17.530
Nine greater than negative 10.

07:17.630 --> 07:25.140
That seems like it should be true and it is what about 1 greater than 1.

07:25.430 --> 07:27.340
Well I don't think one is greater than one.

07:27.380 --> 07:28.450
So it's false.

07:28.460 --> 07:32.350
However if there was the equal sign of course it would be true.

07:33.200 --> 07:42.170
Now these two string comparisons with greater than less and is notorious in all languages for one being

07:42.200 --> 07:46.140
annoying and confusing and to differing radically between languages.

07:46.310 --> 07:51.860
So the advice that I would give to anyone is to just avoid ever having to do anything like this.

07:51.860 --> 07:55.320
There are ways around it but I just wanted to show you what happens.

07:55.340 --> 07:59.490
So what do you think is the lowercase a culture for B.

07:59.600 --> 08:01.850
So is it greater than or less than B.

08:02.570 --> 08:08.320
And in some languages it is greater than in others it's less than in my case my ass.

08:08.340 --> 08:17.610
Q Well if we hit Enter we can see that a is not greater than B meaning that it's less than B although

08:17.610 --> 08:22.300
technically that statement is logically wrong because it could be equal to B.

08:22.500 --> 08:26.560
But as you can see if I add that equal sign it's still false.

08:26.610 --> 08:29.650
So we know definitely a is less than B.

08:30.030 --> 08:36.800
Ok so that brings us to our last one which is a bit tricky upper case a greater than lower case.

08:37.230 --> 08:42.980
And if we run with a semi-colon you'll see that it's false.

08:43.080 --> 08:46.060
So uppercase case is not greater than lowercase J.

08:46.320 --> 08:53.850
So then does that mean that it's lower as upper case a come before lower case.

08:54.240 --> 08:59.420
And the answer is actually if we change this just slightly to be greater than or equal to.

09:00.000 --> 09:01.410
You'll see now it's true.

09:01.710 --> 09:08.150
So that tells us uppercase a is equivalent to lowercase say in my eyes.

09:08.340 --> 09:09.570
And we've seen that before.

09:09.750 --> 09:13.670
When we do something like Well let me just type it again.

09:13.750 --> 09:26.210
Select author L. name where author name equals Buju Eggers like this.

09:26.670 --> 09:33.000
And of course they add in the all important table name from books.

09:34.170 --> 09:35.410
So if I do this.

09:36.210 --> 09:41.130
And let's also do title just to make it easier to see what's going on.

09:41.130 --> 09:42.750
It matches just fine.

09:43.030 --> 09:46.700
But I can also do this with lowercase e and it works just the same.

09:46.800 --> 09:50.950
Or I can do Aggers like that with two uppercase G's.

09:50.970 --> 09:56.430
So the way that string comparisons work in my school is quite odd in and if you're familiar with other

09:56.430 --> 10:00.280
languages it's very different from pretty much every language I've worked with.

10:00.290 --> 10:03.670
So just something worth noting that case doesn't actually matter.
