Learn to utilize the incredibly powerful and useful database tool, Microsoft's SQL Server as well as SQL Server Management Studio through this series of tutorials! This episode covers a detailed understanding of the WHERE operation for filtering data out of a specific table in SQL based on column conditions!
Learn the basics of a standard Select, From, Where statement query in just minutes! SQL is an incredible tool for any employee to be familiar with for their job or as an independent software developer!
If you want to see anything specific on the channel or have technical questions about anything leave a comment on our of our videos and we will get back as soon as we can!
Thanks for watching and supporting the channel!
hello welcome back to the channel uh
today's video is going to be part three
in this channel's introduction to sql
series and um previously we took a look
at the select statement and some of the
different ways you can structure that in
a sql query and today we're going to be
looking at the where
statement so the three main parts of
most sql queries are select from and
where
and select is telling you what data you
want to grab from is telling you what
table to grab it from and then where is
telling you the conditions inside that
data that you want to see
so it's kind of nice you can use
pretty much any parameter inside the
table
to to filter data so
if you missed the previous videos this
is the table that we're working with
it's just a list of employee data at
some random company i made up
where we have an employee name their
position with the company and a salary
and
so inside the sql table what what i have
created here is just a statement that
grabs everything right sequel's little
star character is the character that
grabs everything from a table and then
we say specifically to grab it from that
employee table we just looked at so what
we're introducing today
is sql's where condition
so just to start let's say where
employee
right so we're looking at the name
and we'll just say
like
jim
so now we're specifically looking for
employees whose names are jim
if i run this it should be no surprise
you get gym okay
um
but that's that's not really useful you
have to look for something so specific
as a single employee's name
something that would be more common is
like you want to see all your sales
people so you're going to say position
like
sales and i should say like is for text
values basically what equals is for
numerical values and inside sql you can
actually use the equal sign
all the time
like is a little bit better because it's
it's a comparison so it's seeing if that
is inside of the data so if you say
equals to and it's not perfect
that's not going to give you anything
but if you're working with string values
okay i lied we make that sales
so where position is like sales we get
jim and dwight now because they're both
sales people
um
so right away you see a little bit of
the filtering out of data as a really
useful tool
but now we can say we want to see
everybody who
makes above a certain amount so
with
looking at salary
you now can't use like this is for text
values only
um so if we say where salary is greater
than
forty thousand dollars we're going to
look at the high earners
we get jim michael and dwight in that
but if we lower this down to thirty
thousand dollars
we get everyone except pam
um
and so essentially what you're doing is
adding just some parameter to filter out
certain uh people based on whatever
criteria you're given and the other nice
thing is you can combine
multiple conditions in these so you
could say and
salary
is less than
fifty thousand dollars right so we would
expect this to probably filter out yeah
michael's not in there anymore
so you can create multiple conditions or
you can say salary is greater than 30
000 and you can reference multiple
different columns as well so you could
say and the position
is
sales
so now we're saying people who make
above a certain threshold
and are in sales and so if we take the
if we take the number that'll separate
these two and say okay it's got to be
greater than 44999
and position is like sales well now
we're down to just gym so this becomes
really powerful when it's combined as
well with
just selecting certain data
so like you could say well i don't
actually need to know
the
salary anymore because i'm filtering it
out so much so you cannot jim so you can
say select just the employee names who
meet certain criteria so let's say just
the employees who make more than that
much money
and then you're going to get just jim
and michael
and if you put that criteria back in
you'll get
not sure what that's failing for
there we go maybe at my lowercase a
um
but anyways that's a brief introduction
to the where statement you can filter
out numerical values or string values
and it's a really useful way especially
when combined with select to distill
information down to
some really specific keys because most
of the time whoever you're writing sql
queries for isn't just going to want
some massive block of unfiltered data
they're going to want to kind of know
why
and the structure behind that data so
that's an introduction to the where
if you found that useful or you have any
sort of comments go ahead let me know
about it in the comments below otherwise
if you found this um useful for you i
really appreciate uh liking to subscribe
it helps the channel a lot
and as always thanks for watching and
good luck with your code thanks bye