SQL Aliases
SQL

SQL Aliases — How to Rename Columns and Tables

CHAPTER 19 of 30 SQL Tutorial — Free Course on Neotech Navigators
SQL aliases give a table or column a temporary name using the AS keyword. They make output more readable, simplify complex queries, and are essential when working with JOINs. In this chapter, you will learn column aliases, table aliases, and when to use each.

Column Aliases

A column alias renames a column in the query output. The actual table is not changed:

SQL
SELECT Name AS EmployeeName,
       Salary AS MonthlySalary
FROM Employees;
✓ OUTPUT
+--------------+---------------+
| EmployeeName | MonthlySalary |
+--------------+---------------+
| Priya K.     | 55000         |
| John D.      | 62000         |
| Arun M.      | 78000         |
| Emma W.      | 51000         |
| Ravi S.      | 72000         |
| Sara L.      | 58000         |
+--------------+---------------+

Aliases with Calculations

Aliases are especially useful for calculated columns that have no natural name. You learned about aggregate functions like SUM and AVG earlier — aliases make their output readable:

SQL
SELECT Name,
       Salary * 12 AS AnnualSalary,
       Salary * 12 * 0.10 AS AnnualTax
FROM Employees;
✓ OUTPUT
+-----------+--------------+-----------+
| Name      | AnnualSalary | AnnualTax |
+-----------+--------------+-----------+
| Priya K.  | 660000       | 66000     |
| John D.   | 744000       | 74400     |
| Arun M.   | 936000       | 93600     |
+-----------+--------------+-----------+

Aliases with Spaces

If your alias contains spaces, wrap it in quotes or brackets:

SQL
SELECT Name AS 'Employee Name',
       City AS 'Work Location'
FROM Employees;

AS Is Optional

The AS keyword is optional in most databases. These two are identical:

SQL — Both Work
SELECT Name AS EmployeeName FROM Employees;
SELECT Name EmployeeName FROM Employees;

💡 Best Practice

Always include AS even though it is optional. It makes your queries clearer and easier to read, especially in complex queries with multiple aliases.

Table Aliases

Table aliases give a short name to a table. This is especially useful with JOINs:

SQL — Table Alias
SELECT e.Name, e.Department, e.Salary
FROM Employees AS e
WHERE e.Salary > 60000;
✓ OUTPUT
+-----------+------------+--------+
| Name      | Department | Salary |
+-----------+------------+--------+
| John D.   | Marketing  | 62000  |
| Arun M.   | IT         | 78000  |
| Ravi S.   | IT         | 72000  |
+-----------+------------+--------+

The table Employees is aliased as e. You can then use e.Name instead of Employees.Name.

Table Aliases with JOINs

Table aliases become essential when joining multiple tables:

SQL — JOIN with Aliases
SELECT e.Name, d.DepartmentName, e.Salary
FROM Employees AS e
INNER JOIN Departments AS d
  ON e.DeptID = d.ID;

Without aliases, you would need to write Employees.Name and Departments.DepartmentName every time. Aliases save typing and improve readability. You will learn JOINs in detail in the next chapter.

When to Use Aliases

Situation Alias Type Example
Rename output columns Column alias Salary AS Pay
Label calculated columns Column alias Salary * 12 AS Annual
Shorten table names in JOINs Table alias Employees AS e
Self-joins (same table twice) Table alias Employees AS e1, Employees AS e2
Aggregate function output Column alias COUNT(*) AS Total

For a complete reference of the SELECT syntax, see the official MySQL SELECT documentation.

If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.

📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.

🧪 Try It Yourself

Write a query that shows each employee’s Name (as “Employee”), Department (as “Team”), and Salary increased by 15% (as “NewSalary”).

ANSWER
SELECT Name AS Employee,
       Department AS Team,
       Salary * 1.15 AS NewSalary
FROM Employees;

📝 What You Learned in This Chapter

  • AS creates temporary names for columns and tables
  • Column aliases rename output columns without changing the table
  • Table aliases shorten table names for readability, especially in JOINs
  • AS is optional but recommended for clarity
  • Use quotes for aliases with spaces
  • Aliases only exist for the duration of the query

Frequently Asked Questions

What is an alias in SQL?
An alias is a temporary name given to a column or table using the AS keyword. It exists only for the duration of the query and does not change the actual database. Aliases make output readable and simplify complex queries.
Is the AS keyword required for aliases?
No. AS is optional in most databases. SELECT Name AS Employee and SELECT Name Employee both work. However, using AS is strongly recommended for clarity and readability.
Can I use an alias in the WHERE clause?
In most databases, you cannot use a column alias in the WHERE clause because WHERE is processed before SELECT. Use the original column name or expression in WHERE. MySQL is an exception that allows aliases in some contexts.
When should I use table aliases?
Use table aliases when joining multiple tables, performing self-joins, or when table names are long. They make queries shorter and more readable. For single-table queries, table aliases are optional.
Do aliases change the actual table or column names?
No. Aliases are temporary and only apply to the current query’s output. The actual table structure, column names, and data remain completely unchanged. Aliases disappear as soon as the query finishes executing.

📖 Chapter 19 of 30 — SQL Tutorial on Neotech Navigators

PK
Meet PK, the founder of NeotechNavigators.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your data analysis skills to the next level!
https://neotechnavigators.com