sql-aliases alias (AS)

Source: Internet
Author: User
Tags aliases

The use of the alias (alias) on SQL. There are two types of aliases that are most commonly used: field aliases and table aliases.

Simply put, the purpose of the field alias is to make the results of SQL generated easy to read . In the previous example, the field name is SUM (sales) whenever we have a total turnover. Although there is no problem in this case, if the field is not a simple summation, but a complex calculation, then the column name is not so easy to understand. If we use field aliases, we can confirm that the field names in the results are easy to understand.

The second type of alias is the table alias. To give a table an alias, simply empty a grid after the table name in the FROM clause, and then list the table aliases you want to use. This is handy when we want to use SQL to get data from several different tables. This is what we'll see later when we talk about join.

Let's take a look at the syntax for field aliases and table aliases:

Select from "Table name" "Table alias";

Basically, both of these aliases are placed behind the objects they are replacing, and they are separated by a blank space. We continue to use the store_information form to do an example:

We use the same example as the SQL GROUP by page. The difference here is that we've added field aliases and table aliases:

SELECT SUM ' Total Sales '  from store_information A1 GROUP  by A1. Store_name;
Los Angeles    1800San Diego    Boston    

In the results, the information itself is not different. The difference is the title of the field. This is the result of applying a field alias. In the second field, we originally had the title "Sum", and now we have a very clear "total sales". It is clear that total sales can describe the meaning of this field more precisely than Sum (sales). The benefits of using table aliases don't show up here.

sql-aliases alias (AS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.