SQL Keywords

SQL AS

What is the SQL AS keyword?

AS assigns an alias to a column, expression, table, or subquery for easier reference and clearer output.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL AS: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, BigQuery, Redshift, DB2

SQL AS Full Explanation

AS is a keyword that lets you temporarily rename result columns, expressions, tables, or derived tables inside a single SQL statement. Aliases improve readability, shorten verbose identifiers, and allow self-joins without ambiguity. Most dialects treat AS as optional for aliases, but including it makes intent explicit and keeps code portable. Column aliases exist only in the query result set; they are not persisted in the schema. Table aliases are scoped to the statement and can be referenced in JOIN, WHERE, GROUP BY, HAVING, and ORDER BY clauses. Some databases allow referencing a column alias in ORDER BY but not in WHERE or GROUP BY within the same SELECT. Use double quotes or backticks around the alias if it contains spaces, special characters, or matches a reserved word. Beyond SELECT, AS appears in CREATE TABLE ... AS SELECT and CREATE VIEW, where it defines the new schema based on a query result. AS does not accept parameters and does not change data types (CAST handles type conversion).

SQL AS Syntax

-- Column alias
SELECT column_name AS alias_name
FROM table_name;

-- Table alias
SELECT t.column_name
FROM table_name AS t;

-- Derived table alias
SELECT d.total
FROM (SELECT SUM(amount) AS total FROM payments) AS d;

SQL AS Parameters

Example Queries Using SQL AS

-- 1. Rename a computed column
SELECT first_name || ' ' || last_name AS full_name
FROM users;

-- 2. Shorten a long table name
SELECT o.order_id, c.company_name
FROM orders_2024 AS o
JOIN customers AS c ON o.customer_id = c.id;

-- 3. Self-join using table aliases
SELECT e1.name, e2.name AS manager_name
FROM employees AS e1
JOIN employees AS e2 ON e1.manager_id = e2.id;

-- 4. Derived table alias in aggregation
SELECT d.country, d.total_sales
FROM (
  SELECT country, SUM(sales) AS total_sales
  FROM transactions
  GROUP BY country
) AS d;

Expected Output Using SQL AS

  • The query engine substitutes the alias wherever allowed, returning result sets whose column headers or table references match the specified aliases

Use Cases with SQL AS

  • Present friendly column names in reports or BI tools.
  • Disambiguate columns when joining multiple tables with overlapping column names.
  • Enable self-joins by giving each instance of the same table a unique identifier.
  • Wrap complex subqueries or derived tables to reference them like regular tables.
  • Build CREATE TABLE ... AS SELECT or CREATE VIEW statements with defined column names.

Common Mistakes with SQL AS

  • Omitting quotes around aliases that contain spaces or reserved keywords.
  • Expecting to reference a column alias in the WHERE or GROUP BY clause of the same SELECT in databases that do not support it.
  • Forgetting that an alias is transient and not stored in the database schema.
  • Confusing AS (aliasing) with CAST (type conversion).

Related Topics

SELECT, JOIN, CREATE VIEW, CREATE TABLE AS, CAST, WITH (CTE)

First Introduced In

SQL-92

Frequently Asked Questions

What does AS stand for in SQL?

AS literally means "alias" and signals that the preceding column, expression, or table should be referenced by the following name for the duration of the statement.

Do I have to use AS keyword or can I skip it?

You can skip AS in most dialects: `SELECT column alias_name`. However, using AS makes the code clearer and avoids edge-case parsing issues, so many teams enforce it with linters.

Why can I use a column alias in ORDER BY but not in WHERE?

SQL evaluates WHERE before SELECT, so the alias does not yet exist. ORDER BY runs after SELECT, so the alias is available. If you need the alias in WHERE, wrap the query in a subquery and filter outside.

Does an alias created with AS change the underlying table or column name?

No. Aliases are temporary and exist only for the duration of that single SQL statement or the view/table you create with it. They do not alter the physical schema.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!