SQL > SQL Commands > Alias

Alias refers to the practice of using a different temporary name (usually a short name or a name with a logical meaning) to a database table or a column in a table.

SQL aliases give temporary names to tables and columns within a query, making SQL more readable and output more meaningful. Table aliases become essential when joining a table to itself in a self join.

The main advantage of using an alias is to help make the SQL statement more concise and readable. In addition, the output of the SQL statement can become more understandable with the use of an alias.

Syntax

The syntax for a table alias and a column alias is as follows:

SELECT "table_alias"."column_name1" "column_alias"
FROM "table_name" "table_alias";

Both types of aliases are placed directly after the item they alias for, separate by a white space.

Example

We use the following table for our example.

Table Store_Information

 Store_Name  Sales  Txn_Date 
 Los Angeles  1500  Jan-05-1999 
 San Diego  250  Jan-07-1999 
 Los Angeles  300  Jan-08-1999 
 Boston  700  Jan-08-1999 

We use the same SQL query as Example 1 in the SQL GROUP BY section, except that we have put in both the column alias and the table alias:

SELECT A1.Store_Name Store, SUM(A1.Sales) "Total Sales"
FROM Store_Information A1
GROUP BY A1.Store_Name;

Result:

Store Total Sales
Los Angeles 1800
San Diego 250
Boston 700

Notice that difference in the result: the column titles are now different. That is the result of using the column alias. Instead of the somewhat cryptic "Sum(Sales)", we now have "Total Sales", which is much more understandable, as the column header. The advantage of using a table alias is not apparent in this example. However, they will become evident when we look at join operations in SQL.

Frequently Asked Questions

What is a SQL alias?
A SQL alias is a temporary name given to a table or column in a query. It exists only for the duration of that query and makes SQL statements more concise and easier to read.
What is the difference between a column alias and a table alias?
A column alias renames a column in the result set (useful for cleaner output headers). A table alias gives a table a shorter name within the query (especially valuable in joins and self joins where the same table is referenced multiple times).
Do I need to use the AS keyword for an alias in SQL?
No. You can create an alias by placing the alias name directly after the table or column name, separated by a space. However, using AS makes the intent clearer and improves readability.
When are table aliases required in SQL?
Table aliases are required in self joins, where the same table appears twice in the FROM clause. Aliases let you refer to each instance of the table separately using different names.

Next: SQL AS

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact