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 how to give a Table name an ALIAS in a SQL Query for easy reusability!
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 will be the next step in
our introduction to SQL tutorial and
today specifically we'll be looking at
uh using aliases in SQL so previously
we've uh already covered using select
from where order by um and the top
functionality in SQL and this will kind
of be the next step in the
process and uh what I have up here is
kind of a query that I start most of the
videos from I select all the data from
this initial employee table that I
created um and for this video to show
why aliases are so important I created a
second table that I call the sales table
and what I've done is just made this
table where I just make employee name
and then their total sales for the year
that's it that's all that's in the table
right here
um but uh the reason I wanted to have
two tables for this one is because using
aliases is a really useful shortcut when
you start having to type in um your
table name over and over
again so what I mean by an alias is
you're going to take something like a
table name or you could do it for a
column name as well and you can redefine
it and say select employee table as and
let's say instead of typing employee
table every time we want to say ET and
then we'll also say we want the sales
table and we're going to um say that's
going to be as uh we'll just call that
one St okay so um this is probably just
because I haven't refreshed everything
yeah that's fine um but then so now what
we've done is when we want to uh say
what we specifically want so all I want
to get from here is um is just the
employee name so I'm going to say
e right from the employee table and
we'll grab the employee name and then
let's grab from the sales table St uh
what their actual sales for the year
have been and then let's say we want to
compare all of that to what we're paying
them so we grab from the uh employee
table we grab their salary as
well so rather than have to type in
employee table sales table employee
table I've just been able to say ET
St um and then what will that is a
filter condition um and we'll say where
the
ET um.
employee is equal to the St Dot and we
called it
employee name over there so what we're
saying is inside the sales table uh grab
the um any row that has the same
employee table name so uh something
we'll cover in a later video called an
inner join can create one master table
based on um two separate tables and this
is kind of a simpler way of doing the
same type of thing where we're saying
when the employee uh name is equal to
the employee in the employee table then
pull in the employee name the sales data
and the salary so if we go ahead and run
this I know I got the red squiggly lines
but that's just cuz the thing hasn't
refreshed yet um but you can see we get
only the two salespeople
what their sales for the year were and
what their salary is um which is pretty
cool but uh just to show why we need
this if if we just didn't have a wear
condition in this query and we tried to
grab all this you get all of the data
but the sales is the S the sales is
meaningless I mean there's it doesn't
know anything to correlate it with so it
takes every entry that it has for sales
which fortunately is just two it has
20,000 and 30,000 and if if you don't
tell it how to correlate one piece of
data to the other it takes every col
every row of sales data and applies it
to every entry in the employee table so
obviously uh telling it how this data is
related is very important um and then uh
the other thing you could do is in in
right instead of this being the employee
from the employee table you could say St
and then call it the employee
name and uh that's going to give you
exactly the same thing as when we called
it employee because um right that's what
we're combining them on so that it
should make sense that those two things
are the same and if I were to put the
et. employee in here with the other guys
as well you're just going to get the
exact same column twice right so this is
obviously whatever your common piece
between the two tables is that's what
you want to join them on when you use
your wear statement comparing them uh
you can also one thing worth mentioning
you can also Alias actual column names
so if you want to Alias uh employee name
as en um you could do that and then you
could come down here and say st.
instead but most of the time you're not
going to want to Alias uh columns at
least I don't um it's super useful for
aliasing tables where you pull a lot of
data
in um but that's kind of a quick
introduction to aliasing that's a pretty
important pretty easy sequel concept
hopefully you found that useful and uh
if you have any questions or you know
why uh when I aliased that column name
it goofed up just let me know about in
the comments below and I'll try to
respond as quickly as possible if you
found this or anything else on the
channel useful I really appreciate a
like and a subscribe it helps Channel
out a ton and as always good luck with
your projects and thanks for watching
thanks bye bye