What is a Column Alias and why would we use it?
Just as we used an alias for a table name in our previous lesson, we can also use an alias for a column name.
The syntax is the same ("AS alias_name") and helps us clear up any confusion when fields from different tables have the same name (but hold different data).
The Column Alias is also useful for tidying up our SQL code and results if the column names are long, repetitive or not particularly easy to decipher.
Actor_First_Name as FName,
Actor_Last_Name as Surname,
Actor_Date_Of_Birth as DOB,
Actor_Annual_Earnings as Income
In this example, we've taken some very longwinded Column names (such as Actor_First_Name) and made them into a more readable Column Alias (e.g. FName).
Try the next lesson
Let's link our movies and actors back together but this time we only want to see two columns returned - 1) movie_name (which is the title of the movie) and 2) actor_name (which is the actor's name).
The Data. Show Answer
SELECT a.title as movie_name, c.name as actor_name FROM movies a INNER JOIN movie_actors_link b ON a.id=b.movie_id INNER JOIN actors c ON b.actor_id = c.actor_id