Alias
This lesson explains the concept of using an alias for a table.
We'll cover the following...
Alias
Aliases are like nicknames, a temporary name given to a table or a column to write expressive and readable queries. We can use aliases with columns, tables, and MySQL functions.
Example Syntax
SELECT col1
AS aliasCol1
FROM table;
Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/20lesson.sh and wait for the MySQL prompt to start-up.
Press + to interact
-- The lesson queries are reproduced below for convenient copy/paste into the terminal.-- Query 1SELECT FirstName AS PopularName from Actors;-- Query 2SELECT CONCAT(FirstName,' ', SecondName) AS FullName FROM Actors;-- Query 3SELECT CONCAT(FirstName,' ', SecondName) AS FullName FROM Actors ORDER BY FullName;-- Query 4SELECT CONCAT(FirstName,' ', SecondName) FROM Actors ORDER BY CONCAT(FirstName,' ', SecondName);-- Query 5SELECT FirstName FROM Actors AS tbl WHERE tbl.FirstName='Brad' AND tbl.NetWorthInMillions > 200;-- Query 6SELECT tbl.FirstName FROM Actors AS tbl WHERE tbl.FirstName='Brad' AND tbl.NetWorthInMillions > 200;-- Query 7SELECT t1.FirstName, t1.NetworthInMillionsFROM Actors AS t1,Actors AS t2WHERE t1.NetworthInMillions = t2.NetworthInMillionsAND t1.Id != t2.Id;
-
We have the first name column in the Actors table. Since most actors are known by their first names, we can alias the FirstName column as PopularName in the following ...