SQL > SQL Commands >
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.
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.
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.
We use the following table for our example.
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;
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.