Intermediate SQL Tutorial | Aliasing
Skills:
SQL Analytics90%
Key Takeaways
This video tutorial covers intermediate SQL concepts, specifically aliasing columns and tables, to maintain clean and understandable code in data analytics.
Full Transcript
what's going on everybody my name is Alex free brands today what are we talking about aliasing now all aliasing really is is temporarily changing the column name or the table name in your script and it's not really gonna 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 ten 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 f name and all that's gonna do is it's gonna rename this column from first name which it was originally named to f name 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 gonna work perfectly you can either use the adds or you can not use it I typically don't I just put a space in between the actual column and the alias sounds 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 gonna 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 gonna take the first name out of space and then do the last name and we're gonna do that as I 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 have 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's somebody who is actually looking at this script or who's looking at the output of the script actually understand the 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 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 gonna get no column name and 31 so we want to do is give it a verage 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 gonna 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 it 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 we have several joins because they can get in 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 sow dot employee ID so now let's do demo dot employee ID comma Sal dot and let's do a 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 we have a very long script let's look at this query where we're joining the others three separate tables and after each table we have an alias for employee demographics we have a police 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 it's looking an example of what it should look like so for employee demographics instead of having an alias of an 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 gonna 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 in the next video
Original Description
Take my Full MySQL Course Here: https://bit.ly/3tqOipr
Today we look at how to alias columns and tables. This becomes very important as your queries begin to grow and you begin handing off scripts to teammates. It's important to use proper aliases to maintain clean, understandable code.
____________________________________________
SUBSCRIBE!
Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
____________________________________________
RESOURCES:
Coursera Courses:
Google Data Analyst Certification: https://coursera.pxf.io/5bBd62
Data Analysis with Python - https://coursera.pxf.io/BXY3Wy
IBM Data Analysis Specialization - https://coursera.pxf.io/AoYOdR
Tableau Data Visualization - https://coursera.pxf.io/MXYqaN
Udemy Courses:
Python for Data Analysis and Visualization- https://bit.ly/3hhX4LX
Statistics for Data Science - https://bit.ly/37jqDbq
SQL for Data Analysts (SSMS) - https://bit.ly/3fkqEij
Tableau A-Z - http://bit.ly/385lYvN
*Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!*
____________________________________________
Websites:
GitHub: https://github.com/AlexTheAnalyst
____________________________________________
*All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for*
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Alex The Analyst · Alex The Analyst · 28 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
▶
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Top 3 Data Analyst Skills in 2020
Alex The Analyst
Truth About Big Companies | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Salary | 100k with No Experience
Alex The Analyst
Working at a Big Company Vs Small Company | Told by a Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Reviewing My Resume! | Fortune 500 Data Analyst
Alex The Analyst
Data Analyst Resume | Complete Guide To Creating A Data Analyst Resume | Tips + Templates + Examples
Alex The Analyst
Switching Careers to Become a Data Analyst | How I Made the Switch
Alex The Analyst
Working With a Recruiter to Land Your First Job as a Data Analyst | LinkedIn Recruiters
Alex The Analyst
Data Analyst Salary in 2020
Alex The Analyst
Data Analyst Resume | Reviewing YOUR Data Analyst Resumes!
Alex The Analyst
Data Analyst Fact Check | 84k Average Starting Salary?? | The Career Force 2020 Data Analyst Salary
Alex The Analyst
SQL Basics Tutorial For Beginners | Installing SQL Server Management Studio and Create Tables | 1/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Select + From Statements | 2/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Where Statement | 3/4
Alex The Analyst
SQL Basics Tutorial For Beginners | Group By + Order By Statements | 4/4
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition
Alex The Analyst
Intermediate SQL Tutorial | Inner/Outer Joins | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Unions | Union Operator
Alex The Analyst
Intermediate SQL Tutorial | Case Statement | Use Cases
Alex The Analyst
Intermediate SQL Tutorial | Having Clause
Alex The Analyst
Intermediate SQL Tutorial | Updating/Deleting Data
Alex The Analyst
Day in the Life of a Data Analyst | Fortune 500 Edition (During Quarantine)
Alex The Analyst
Data Analyst Interview Questions | Phone + In-Person Interview Questions
Alex The Analyst
SQL Interview Questions and Answers for Beginners | Data Analyst Interview Questions
Alex The Analyst
Data Analyst Interview Questions | What To Say vs What NOT To Say
Alex The Analyst
Data Analyst Interviews | Salary Negotiation
Alex The Analyst
Data Analyst Q&A LIVE
Alex The Analyst
Intermediate SQL Tutorial | Aliasing
Alex The Analyst
Data Scientist vs Data Analyst | Which Is Right For You?
Alex The Analyst
Best Online Courses for Data Analysts
Alex The Analyst
Best Free Online Courses for Data Analysts
Alex The Analyst
Data Analyst vs Business Analyst | Which Is Right For You?
Alex The Analyst
Scraping Data Off Twitter Using Python | Twitterscraper + NLP + Data Visualization
Alex The Analyst
Data Analyst Question and Answer | Answering Your YouTube Questions
Alex The Analyst
What Does a Data Analyst Actually Do?
Alex The Analyst
Data Analyst Bootcamps | Are They Worth It?
Alex The Analyst
Top 5 Reasons Not to Become a Data Analyst
Alex The Analyst
Data Analyst Career Path | How to Become a Data Analyst + What to Do Next
Alex The Analyst
Live Data Analyst Q&A #3
Alex The Analyst
Top 5 Reasons Not to Lie on Your Resume
Alex The Analyst
The Hiring Process from an Interviewer's Perspective | Alex The Analyst Show | Episode 1
Alex The Analyst
Top 5 Reasons Data Analytics is a Good Career Choice
Alex The Analyst
How I Changed Careers to Become a Data Analyst | Alex The Analyst Show | Episode 2
Alex The Analyst
Top 5 Reasons You'll Be a Good Data Analyst
Alex The Analyst
Self Taught vs Boot Camp vs Degree | Alex The Analyst Show | Episode 3
Alex The Analyst
Covid and the Data Analyst Job Market | Alex The Analyst Show | Episode 4
Alex The Analyst
Data Analyst Expectations vs Reality
Alex The Analyst
Imposter Syndrome in Tech | Alex The Analyst Show | Episode 5
Alex The Analyst
Top 10 Coursera Courses for Data Analysts
Alex The Analyst
Working at a Startup vs Fortune 500 Company | Alex The Analyst Show | Episode 6
Alex The Analyst
Data Analyst Certifications | Are They Worth It? | Alex The Analyst Show | Episode 7
Alex The Analyst
Top 10 Udemy Courses for Data Analysts
Alex The Analyst
Asking My Wife Your Questions About Me | Alex The Analyst Show | Episode 8
Alex The Analyst
Data Analyst Q&A LIVE #4
Alex The Analyst
Data Analyst Skills Path | What Skills You NEED to Know
Alex The Analyst
What is Analytics Consulting? With John Ariansen | Alex The Analyst Show | Episode 9
Alex The Analyst
Solving LeetCode SQL Interview Questions | Part 1/3
Alex The Analyst
What is No Code Analytics? | Alex The Analyst Show | Episode 10
Alex The Analyst
Top 3 Tips on Using LinkedIn to Land a Job
Alex The Analyst
Completely Unrealistic Jobs on LinkedIn | Alex The Analyst Show | Episode 11
Alex The Analyst
More on: SQL Analytics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
The HiPPO is always right
Dev.to · Sharmin Sirajudeen
How to Extract Saudi Arabia Property Data Across Bayut.sa, Wasalt.sa, Aqar.fm and PropertyFinder.sa
Dev.to · Omar Eldeeb
Norway vs France (1:4) — A 97% Crime Index Anomaly: When Ruthless Efficiency Buries the xG Evidence
Medium · Data Science
How to Build an H-1B Salary Database by Employer (the Real Data Source + Python)
Dev.to · Omar Eldeeb
🎓
Tutor Explanation
DeepCamp AI