AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Alias |
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. 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. SyntaxThe 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. ExampleWe use the following table for our example. Table Store_Information
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:
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. |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.