SQL Aliases
SQL

SQL Aliases: Rename Columns and Tables with AS (Examples)

SQL Tutorial · Chapter 14 of 32

SQL aliases give a column or a table a temporary name that exists only for the duration of one query. A column alias makes result headings readable and names calculated columns; a table alias shortens long table names so joins are easier to write. Aliases are created with the AS keyword, which is optional in most databases but recommended for clarity.

SQL Alias Syntax

-- column alias
SELECT column_name AS alias_name FROM table_name;

-- table alias
SELECT t.column_name FROM table_name AS t;

-- alias with spaces (quote it)
SELECT Amount AS "Order Amount" FROM Orders;

Sample Tables

Customers
CustomerID Name City Country
1 Anita Sharma Mumbai India
2 John Smith London UK
3 Maria Garcia Madrid Spain
4 Wei Chen Singapore Singapore
5 Emma Brown Sydney Australia
Orders
OrderID CustomerID Product Amount OrderDate
101 1 Laptop 1200 2026-01-05
102 2 Mouse 25 2026-01-07
103 1 Monitor 300 2026-01-12
104 3 Keyboard 45 2026-02-02
105 6 Headset 80 2026-02-15
106 4 Laptop 1150 2026-03-01

Example 1: Rename a Column

SELECT Name AS CustomerName, City AS Location
FROM Customers
WHERE Country = 'UK';
CustomerName Location
John Smith London

The table column is still called Name; only the heading in this result changes.

Example 2: Name a Calculated Column

Without an alias a calculated column gets an ugly automatic heading such as Amount * 1.18 or ?column?.

SELECT OrderID, Amount, ROUND(Amount * 1.18, 2) AS AmountWithTax
FROM Orders
WHERE Amount > 100;
OrderID Amount AmountWithTax
101 1200 1416.00
103 300 354.00
106 1150 1357.00

Example 3: Table Aliases in a Join

Table aliases keep join queries short. Once you alias a table you must use the alias, not the original name, everywhere in that query.

SELECT c.Name, o.Product, o.Amount
FROM Customers AS c
INNER JOIN Orders AS o ON o.CustomerID = c.CustomerID
WHERE o.Amount > 1000;
Name Product Amount
Anita Sharma Laptop 1200
Wei Chen Laptop 1150

Example 4: Alias with Spaces

SELECT Product AS "Product Name", Amount AS "Order Amount"
FROM Orders
WHERE OrderID = 101;
Product Name Order Amount
Laptop 1200

Double quotes are the standard delimiter. MySQL also accepts backticks and SQL Server accepts square brackets.

Example 5: Using an Alias in ORDER BY

SELECT Product, Amount * 1.18 AS WithTax
FROM Orders
ORDER BY WithTax DESC
LIMIT 2;
Product WithTax
Laptop 1416.00
Laptop 1357.00

Where Can an Alias Be Used?

Clause Column alias allowed? Why
ORDER BY Yes Runs after SELECT
WHERE No (standard) Runs before SELECT
GROUP BY / HAVING MySQL, PostgreSQL, SQLite: yes; SQL Server: no Vendor extension

Works in MySQL, SQL Server, PostgreSQL, SQLite

  • AS is optional for column and table aliases in all four; Oracle forbids AS for table aliases, so omitting it there is a portability habit.
  • SQL Server also supports SELECT alias = expression, a non-standard form.
  • Column aliases cannot be referenced in WHERE in any of the four; repeat the expression or use a subquery.

Alias Naming Conventions

Good aliases read like column headings: TotalRevenue, OrderCount, AvgAmount. Avoid spaces and punctuation so you never need quotes, and avoid reusing a real column name for a different expression, which confuses both readers and the optimizer. For table aliases, the convention is the table’s initial or a short abbreviation (c for Customers, o for Orders), used consistently across a project so any query is instantly readable.

Common Mistakes

  • Using an alias in WHERE: WHERE WithTax > 1000 fails; write WHERE Amount * 1.18 > 1000.
  • Referring to the original table name after aliasing it in a join.
  • Forgetting the comma between two columns, which turns the second column name into an alias of the first.
  • Choosing aliases that clash with real column names, making the query ambiguous.

Practice Exercise

  1. Return City renamed to Town and Country renamed to Nation for all customers.
  2. Using table aliases c and o, list each customer name with their OrderID for orders in 2026-01.
Show answers
-- 1
SELECT City AS Town, Country AS Nation FROM Customers;

-- 2
SELECT c.Name, o.OrderID
FROM Customers c
JOIN Orders o ON o.CustomerID = c.CustomerID
WHERE o.OrderDate BETWEEN '2026-01-01' AND '2026-01-31';
-- Anita Sharma 101, John Smith 102, Anita Sharma 103

Related Chapters

FAQ

Is the AS keyword required for SQL aliases?

No. SELECT Name CustomerName works in every major database. AS simply makes the alias easier to spot, and it is required nowhere except by some style guides.

Can I use a column alias in the WHERE clause?

Not in standard SQL, because WHERE is evaluated before the SELECT list. Repeat the expression in WHERE or wrap the query in a subquery.

Do aliases change the table permanently?

No. An alias exists only for the query in which it is defined. To rename a column permanently use ALTER TABLE.

Chapter 14 of 32 · SQL from Scratch: all 32 chapters

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