AI Features

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.

-- The lesson queries are reproduced below for convenient copy/paste into the terminal.
-- Query 1
SELECT FirstName AS PopularName from Actors;
-- Query 2
SELECT CONCAT(FirstName,' ', SecondName) AS FullName FROM Actors;
-- Query 3
SELECT CONCAT(FirstName,' ', SecondName) AS FullName FROM Actors ORDER BY FullName;
-- Query 4
SELECT CONCAT(FirstName,' ', SecondName) FROM Actors ORDER BY CONCAT(FirstName,' ', SecondName);
-- Query 5
SELECT FirstName FROM Actors AS tbl WHERE tbl.FirstName='Brad' AND tbl.NetWorthInMillions > 200;
-- Query 6
SELECT tbl.FirstName FROM Actors AS tbl WHERE tbl.FirstName='Brad' AND tbl.NetWorthInMillions > 200;
-- Query 7
SELECT t1.FirstName, t1.NetworthInMillions
FROM Actors AS t1,
Actors AS t2
WHERE t1.NetworthInMillions = t2.NetworthInMillions
AND t1.Id != t2.Id;
Terminal 1
Terminal
Loading...
  1. 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 ...