All right, Querrey time.
So in the previous video, we ended on talking about queries, a query is nothing more than an instruction
write in English.
A query is defined as a question.
And Enescu, well, queries are the way that we are going to put together our questions to which we
want an answer from the database.
A query is also known as an excuse or statement.
Those are just synonyms.
Query is equal to ask your statement.
SQL statement is equal to a query, just different ways of saying the same thing.
So if we look here, there is a very basic query select star from users.
And if we were to break this down, what it's basically saying is select us all of the information.
So the star here is what we call a wild card.
We don't know what we want to get back, but just get us everything back.
So select us everything from so we're going to say where we want it from.
And we know somewhere in our database we are storing users.
Right.
So select us everything from users.
That's pretty straightforward.
So let's execute that.
All right, so here we see select star from user over here, let's just copy paste all of this information,
just put it in your DB fiddle.
Let's not worry about that just yet.
And if we execute our command select star from user, what we're going to get is a bunch of information
because a bunch of user information was input.
We can see they have an ID, they have a name, a last name, date of birth, sex on a roll.
Awesome, so we can see here that select star from user is actually selecting us all of the information
that we have around that user.
And if we filtered and we just said name, what we would see happen is we would only get the name back.
Amazing, so let's hop back into the slides and check out what a breakdown of equerry looks like.
So here we've expanded the query a bit because we want to break down something a little more complicated.
So let's say we did select name, so select the user's name from.
Our data datasource users in the database where.
Role is equal to manager, so this is new, right, where role is equal to manager.
This is what we call a condition.
So where is our key word?
And we're seeing where the role of the user is equal to manager witness the name.
I hope that makes sense.
We're filtering data at this point.
We're seeing where the role is equal to manager of the user.
Give us back their name.
And so if we were to break down this query and we looked at it line by line.
Select name is a clause from users, is called a clause, and where role is equal to manager is called
the clause.
These are just parts of the school statement or the query.
So each line here is called a clause.
And when we see select name, name is called an identifier.
Now, what does an identifier and identifier is just a different word for a part of the data.
We know that users have a name, so when we select name, we're saying that name is the identifier that
we want.
And when we look at the last line where role is equal to manager, our filtering line, this is a bit
more complicated, right?
Where is our keyword?
Role is our identifier.
But the line role equals manager is called the condition, so a condition is something that needs to
be met.
We're saying that, OK, a user has a role, that role needs to be equal to manager in order for us
to get some data back.
Pretty straightforward and manager is called our expression.
We are expecting that some of the roles may be equal to manager, but some may not be.
So that's why we call it an expression, because we are making an assumption here that some of the roles
are equal to manager.
We want to filter based on our assumption.
Awesome.
So let's fire that real quick.
All right, so we have our query here ready to go, so let's run it.
And as you can see, we are getting back, George, Janene and Jason.
So let's verify that that's actually what we want.
So let's get back all of the information.
All right, so we see here, George, Janene and Jason, and we see that the role is equal to manager.
That makes sense, but who else did we have here again?
So let's go look at that.
This is a way to put a line in comment, you just you don't want to execute that line.
It's a quick way of turning lines on and off.
So let's run that.
So here we can see, OK, George is a manager, and then we had Maisy and Bill who are employees, OK?
That makes sense.
So let's turn that line back on if we run it.
And we said, OK, now filter us, the employees.
So we see Macy and Bill come up.
All right, awesome.
So now it's all starting to come together, right?
We know how to build a very, very simple query.
And I would push you to copy paste what's in here.
Put it in your DB fiddle and try to write some simple queries where you filter and you select certain
fields, and that way you can play around with it.
So we've done our break them and now we know all of the different parts that go into equerry, and that's
super powerful, right?
Because now we've just said select name from users where role is equal to manager.
We asked a question and we got an answer back.
This is what we call a declarative language.
School is a declarative language.
Now, what does that actually mean?
Well, let's dive a bit deeper into that.