Let's talk about the R and CRUD, which is read.
How do we retrieve or read data that's already in a table?
We kind of know the answer.
We use select.
We've seen this before.
I just used it in the previous video.
We've only seen one flavor of select though, which is select Star from a table.
Select star from.
I think I still have my employees in here, Select Star from Cats.
We've been using it just to check our work.
That is an example of reading from a table, selecting rows from a table and viewing them.
Right?
It's retrieving information, but there's a lot more to this select.
Sometimes this is what we want.
Select Star from Cats.
In this star, the select star from Cats is a way of saying, Give me all the columns for this table.
Give me every single column, and in this case, for all the rows.
So that's why we see cat ID, name, breed and age or ID last name, first name, middle name, age,
current status.
Those are all of the columns.
That's what that star does.
But we don't have to get all the columns.
We can actually narrow down what we want to get back.
We can say, I only want name, select name from cats.
Let's try it.
So let me do Star just once again.
So we have that up top and then let's select name from Cats.
It has to match.
Of course, that has to be spelled the same as one of these column names.
And now I'm only getting this portion of the table.
Well, I'm highlighting everything, but I'm trying to highlight this section here.
Names only the names.
We could also, of course, do select age from cats.
Let's try that.
Select age from cats.
Technically, I keep going back to make sure I have all uppercase, all lowercase.
It doesn't actually matter as we've seen, but this just looks ugly.
I don't want you to have to endure such ugly code.
But anyway, we get all of the ages and only the ages, so maybe not that helpful on its own, but this
is something that is helpful.
Let's say that eventually we want to find the average age, the oldest age, the youngest age.
We can work with just ages using select age.
Right now, though, we can't do any of those operations.
So we're simply retrieving all of the ages so we also can combine multiple columns.
I could get name and age.
I just separated, separate them by commas or with commas.
So let's do select name Common age from cats.
How am I missing that uppercase M every time?
And there we go.
Only the name and the age or select name and breed from cats.
Now we only get the name and the corresponding breed columns for every row.
So if we do select star, just one.
One more reminder that gives us all the columns.
And you may have four really complicated tables.
You might actually have dozens of columns, if not more.
So when you do a select star, you won't even be able to see all of the columns, print it out easily.
So sometimes it's just nice to slim things down to the actual columns you care about.
That's it for this video.
And the next one, we've got some additional syntax for select.