Tutorial on SQL Alias Command

 
In this tutorial we are going to focus on the use of aliases.
There are two kinds of aliases that are used most often: column alias and table alias.
 
In brief, column aliases exist to help organizing output.
We can envision cases where the column heading might be complicated (particularly if it involves several arithmetic operations).
 
A use of a column alias makes the output much more readable and meaningful.
 
The table alias is another type of alias which is accomplished by putting an alias after the table name in the FROM clause. This is a convenient approach where you wish to obtain information from two different tables (the technical term is ‘perform joins’).
 
The benefit of using a table alias while performing joins is readily apparent when we talk about joins.
 
The syntax for both the column and table aliases is as follows:
 
SELECT “TableAlias”.”ColumnName1″ “ColumnAlias”
FROM “TableName” “TableAlias”;
 
In short, both categories of aliases are placed directly after the item they alias for, isolated by a white space. Let’s understand it via applying in table, Store Information:
 
Table Name : StoreInformation

StoreName 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 have applied both the column alias and the table alias:
 
SELECT A1.StoreName Store, SUM(A1.Sales) “Total Sales”
FROM StoreInformation A1
GROUP BY A1.StoreName;
 
Output:

Store Total Sales
Los Angeles 1800
San Diego 250
Boston 700

 
Observe that difference in the result: the column titles are now different. That is the organized outcome of using the column alias.
 
So, rather than, somewhat cryptic “Sum(Sales)”, we now have “Total Sales”, that is much more understandable, as the column header.

Kristin is a content strategist at Techarex Networks. Kristin follows the B2B technology space closely and loves to write on the latest changes in technology, futuretech and fixes for day to day how to issues. Besides writing Kristin also loves music, moves and skating.