Back to SQL Notes
Topic #91

SQL Aliases (AS)

An alias gives a column or table a temporary name for the duration of a query — for readability, or to rename computed columns and shorten long table references.

Syntax

SELECT column AS alias_name
FROM table_name AS alias_name;

-- AS is optional in most databases
SELECT column alias_name FROM table_name t;

Column Alias Example

SELECT name, salary * 12 AS annual_salary
FROM employees;

Output column header: annual_salary instead of the default, unreadable salary * 12.

Table Alias Example

SELECT e.name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.id;

Table aliases (e, d) make multi-table queries far more readable — essential once you're writing joins (covered in SQL Joins).

Practical Use Case

Aliases are used constantly: renaming computed values for clarity in reports, shortening long or repeated table names in joins, and giving subquery results a name (required in most databases — a subquery in FROM must be aliased).

Common Mistakes

  • Using a column alias inside the same query's WHERE clause. Because WHERE executes before SELECT in logical order, the alias doesn't exist yet at that point:
    -- Usually invalid
    SELECT salary * 12 AS annual_salary
    FROM employees
    WHERE annual_salary > 700000;
    
    -- Fix: repeat the expression, or wrap in a subquery/CTE
    SELECT salary * 12 AS annual_salary
    FROM employees
    WHERE salary * 12 > 700000;
    Most databases do allow referencing a SELECT alias in ORDER BY, since that runs after SELECT — the restriction is specifically about WHERE, GROUP BY and HAVING in strict standard SQL (though MySQL is more lenient with GROUP BY/HAVING than some databases).
  • Forgetting quotes around an alias that contains spaces: AS Total Salary should be AS "Total Salary" (or backticks in MySQL)

Interview Relevance

Understanding why an alias can't be used in WHERE ties directly back to SQL's logical execution order — a strong signal you understand the engine, not just the syntax.

Practice Question

Write a query that selects first_name and last_name concatenated as full_name, from a table aliased as e.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL Aliases (AS) – FAQs

Quick answers about learning SQL Aliases (AS) in SQL.

This free note from Coding Now Tech Institute explains SQL Aliases (AS) in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL Aliases (AS), is 100% free with no signup required.
With focused practice, most students grasp SQL Aliases (AS) in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now