SQL > SQL Commands > AS

The keyword AS is used to assign an alias to the column or a table. It is inserted between the column name and the column alias or between the table name and the table alias.

SQL AS explicitly labels a column or table with a temporary alias, making query results and complex expressions easier to read — there is no functional difference between using AS and omitting it.

Syntax

The syntax for using AS is as follows:

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

Example

Let's take a look at the same example as we used in the SQL Alias section. Assume we have the following table, Store_Information,

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 

To find total sales by store using AS as part of the table and column alias, we type in:

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

Result:

Store   Total Sales
Los Angeles   1800
San Diego   250
Boston   700

Is there a difference between using an alias without AS and with AS in SQL? The answer is no, there is no functional difference, as both versions will accomplish exactly the same thing. The use of AS is simply a more explicit way of mentioning the alias.

Frequently Asked Questions

What does SQL AS do?
AS assigns a temporary alias to a column or table for the duration of a query. This alias appears in the result set header and can be referenced elsewhere in the query (e.g., ORDER BY).
Is AS required, or can I skip it?
AS is optional in most databases. Writing SUM(Sales) TotalSales is equivalent to SUM(Sales) AS TotalSales. Including AS is considered best practice for readability.
Can column aliases created with AS be used in WHERE?
Not in most databases, because WHERE is evaluated before SELECT. Instead, use the alias in ORDER BY or wrap the query in a subquery to filter by the alias.
Can I use spaces in an alias defined with AS?
Yes, but the alias must be enclosed in double quotes: SUM(Sales) AS "Total Sales". Without quotes, spaces will cause a syntax error.

Next: SQL SELECT UNIQUE

This page was last updated on March 19, 2026.




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