 What's going on everybody? My name is Alex Feebrandt and today we're going to be talking about aliasing. Now all aliasing really is is temporarily changing the colon name or the tail name in your script and it's not really going to impact your output at all. Aliasing is really used for the readability of your script so that if you hand this off to somebody or somebody comes behind you and starts working on this, they can more easily understand it and it may not sound super useful, especially for small scripts like what we have on the screen. But when you start getting to larger scripts where you have six, seven or eight joins and you're selecting 10 different column names, it actually is very useful and very important. So let's get into how that actually works and then I'll have an example later of how we can use aliasing with a little bit of a larger query. So in this table, let's select first name and execute. What we want to do is just write as and let's do fname and all that's going to do is it's going to rename this column from first name which was originally named to fname. Now you can use as but you can also just get rid of that and do it exactly how I have it and it's still going to work perfectly. You can either use the as or you can not use it. I typically don't. I just put a space between the actual column and the alias. Let's look at an example of how this might actually be useful. So we have a first name and a last name in this column so what we're going to do is actually combine those. So let's do plus and let's add a space in there and let's do a plus and let's do last name. So this is going to take the first name add a space and then do the last name and we're going to do that as and let's do full name and let's execute this. So now we have a column called full name which is our alias. So we've combined the first name and the last name column into one single column and we've renamed it full name. If we had not used this alias at all it would have just said this which is no column name at all. We don't typically want that when we have an output. We want to give this column a name so that somebody who is actually looking at the script or who's looking at the output of the script actually understands what is contained within this column. So for that we're just going to keep it as full name. Now another time that you're often going to use aliasing in the select statement is when you're using aggregate functions. So in this table we have age so let's pull that up really quick. So we have age right here and let's actually just do the average age and when we execute this we're going to get no column name at 31. So we want to do is give it average age and when we do that we now have a column name and again you want to have a column name in case someone comes up behind you and is reading the scripts that they understand what this column is being used for. Now that we've looked at aliasing column names let's look at aliasing table names. It basically is the exact same thing. We're just going to write as and let's do demo for demographics and let's do demo dot and it's going to give us all of our options and we'll do employee ID. So when you alias in a table name when you are selecting in the select statement you actually need to preface your column name with a table name or the table alias dot and then employee ID and this is extremely important to do especially when you have a lot of joins that you're doing or you're selecting a lot of columns when you have several joins because it can get very very messy quick. So let's actually join this to employee salary and let's do that on demo dot employee ID is equal to sal dot employee ID. So now let's do demo dot employee ID comma sal dot and let's do salary. So looking at the script now is very clean is very easy to understand and that is what's so important with aliasing. If for example we took this off every time we wanted to reference this table we would have to put the entire table name and putting the entire table name is correct it just is very cumbersome and does not look clean at all and so using something like demo as an alias makes it a lot more easily readable and a lot more manageable when you're looking at it when you have a very long script. Let's look at this query where we're joining together three separate tables and after each table we have an alias for employee demographics we have a employee salary we have b and warehouse employee demographics we have c. Now unfortunately I have seen a lot of scripts that look exactly like this and this is what you do not want to do you do not want to use your aliasing to just write an a a b or a c that is very frowned upon when writing queries because it really doesn't give any context to what the table that you're referencing is and it gets really confusing as this query continues to grow and as you add more columns to your select statement it makes it more difficult to understand where those columns are coming from and so when I'm reading that I say select a dot employee ID okay what's a a is employee demographics so you really do not want to do that now let's look at an example of what it should look like so for employee demographics instead of having an alias of a I used demo for demographics for employee salary I use sal and for warehouse employee demographics I used where now this is not perfect by any means but in the select statement if you're just glancing at it you can easily understand which columns are coming from which tables so when I look at employee ID I know that's coming from employee demographics because I have a demo as the alias so it's a lot easier to understand and when you hand this query off to somebody it is going to be a lot easier for them to read through it and understand where those columns and those table names are coming from and so they will appreciate that in the long run so that is all I got that is aliasing again not a super tough subject but a really important one to understand especially as you start working in teams and as you start creating more and more complex queries you want to have it more organized and more easily readable and so it may not come into play with those really simple queries but again as you build out those more complex queries this becomes very useful I really hope you enjoyed this video if you did be sure to comment and subscribe below thank you so much for watching and I'll see you in the next video