WEBVTT

00:00.150 --> 00:04.770
So we're moving onto the R of crud which is read.

00:04.860 --> 00:08.430
How do we retrieve and search data from a database.

00:08.760 --> 00:13.460
And we've actually already seen this the magic command is select.

00:13.950 --> 00:19.080
So remember when we were doing this earlier select a star from cats I told you not to worry about it

00:19.080 --> 00:24.060
too much because we'd spend more time on it and it was really just something that we needed to have

00:24.600 --> 00:30.150
to check our work at the at that time when we were inserting data but we didn't actually talk about

00:30.150 --> 00:32.000
how it works what the star means.

00:32.460 --> 00:33.910
That's what we're going to do now.

00:34.320 --> 00:42.540
So the star in select star from cats me and give me all the columns in the cats table.

00:42.540 --> 00:45.790
So we're asking for the cats table.

00:45.840 --> 00:47.200
That's the from cats.

00:47.490 --> 00:50.840
And in that table we just want everything that we have.

00:50.940 --> 00:57.890
So in our case that means cat Heidi name age and breed we want all of them coming back to us.

00:57.960 --> 01:00.140
So let's do that now.

01:00.300 --> 01:05.320
Select a star from cats.

01:05.970 --> 01:10.380
You can see we get cat ID name breed and age.

01:10.770 --> 01:13.530
And we also get every single cat.

01:13.560 --> 01:14.510
No one is missing.

01:14.550 --> 01:16.700
These are the seven that we inserted.

01:16.770 --> 01:22.540
So that's the basics of select star which you'll use often just to check things out.

01:22.650 --> 01:28.410
But we can also get more specific about what data we want back which is where the select expression

01:28.410 --> 01:29.270
comes in.

01:29.700 --> 01:36.000
Basically there's a way for us to specify what columns we want in particular I only want the ID or I

01:36.000 --> 01:40.220
only want cats names and age but not the breed.

01:40.230 --> 01:48.420
So to do that rather than saying select star we can do things like select name from cats and if we do

01:48.420 --> 01:54.570
that select name from cats What do you think the table will look like.

01:55.920 --> 01:56.750
Looks like this.

01:56.750 --> 02:02.720
We only get name so it gives us all seven names but nothing else.

02:03.410 --> 02:07.480
We could also do select age from cats.

02:12.590 --> 02:14.420
And hopefully this is what you expected.

02:14.420 --> 02:21.830
We just get a bunch of ages and just to hammer it home here we can also do a select let's do cat ID

02:22.070 --> 02:28.480
from cats and we get one two three four five six seven.

02:28.880 --> 02:29.420
OK.

02:29.720 --> 02:36.290
So that's useful enough but oftentimes we want more than one piece of data but we don't want everything.

02:36.830 --> 02:39.420
And that's where this comma separated post comes in.

02:39.440 --> 02:47.170
So this whole thing is the select expression where saying select name and age from cat so we can try

02:47.170 --> 02:47.320
it.

02:47.310 --> 02:53.630
Now select name comma age from cats.

02:53.800 --> 02:55.580
And what do you think we'll see.

02:56.470 --> 03:00.680
So we get a table with name and age returned back.

03:00.850 --> 03:06.620
So there's no limit on that we could do name age comma cat ID common breed which would be the same thing.

03:06.630 --> 03:13.630
So like star we could do name age and breed or cat ID and name and age and so on I think you get it.

03:13.630 --> 03:16.310
We can mix and match whatever fields we want back.

03:16.690 --> 03:24.670
So just to illustrate my point let's do a select cat Heidi common name comma age from cats and we hit

03:24.670 --> 03:27.360
enter and we get those three fields.

03:27.640 --> 03:32.310
Notice we're missing breed but we could just go at that and if we wanted

03:35.260 --> 03:37.380
and noticed that the order matters.

03:37.480 --> 03:41.040
So I said can I do the name then age then breed.

03:41.290 --> 03:42.690
And that's what we get.

03:42.820 --> 03:44.500
But if I just did a select star

03:47.550 --> 03:53.080
it uses the default order which is cat ID name breed and then age which is just how we entered it when

03:53.080 --> 03:59.650
we created the table so we could reverse it if I wanted to I select age then breed then name it then

03:59.650 --> 04:03.850
Cat ID from cats.

04:04.150 --> 04:05.320
And there we go.

04:05.750 --> 04:06.030
OK.

04:06.040 --> 04:11.380
So that's pretty much all there is to this select expression for now at least where we're just specifying

04:11.410 --> 04:16.930
exactly which columns we want or we can default and use the star which will give us all columns.
