SQL aliases let you assign an alternate identifier to a column or table that lasts only for the duration of the statement that creates it. They improve query readability, shorten long object names, and make complex joins and derived columns easier to reference. Aliases are defined with the AS keyword (optional in most dialects) immediately after the column or table expression.Column aliases- Exist only in the result set or for later clauses like ORDER BY, GROUP BY, or HAVING (dialect dependent).- Cannot be used in the same SELECT list expression that defines them.- Support quoted identifiers for spaces or reserved words.Table aliases- Replace the original table or subquery name for the rest of the statement.- Are required when the same table is joined more than once.- Accept optional column-list aliasing in some systems (e.g., PostgreSQL, Oracle).Aliases are parsed, not stored, so they never affect the underlying schema. They are part of the SQL-92 standard and are widely supported across relational databases.
AS keyword, SELECT, JOIN, CTE, VIEW, WITH clause, GROUP BY, HAVING
SQL-92 standard
Column aliases rename the output column in the result set, while table aliases rename the source table or subquery for easier reference inside the query.
In most databases, AS is optional. Writing `SELECT col alias` works, but `SELECT col AS alias` is clearer and avoids accidental syntax errors.
SQL evaluates the WHERE clause before the SELECT list, so the alias does not yet exist. Move the condition to HAVING or reference the original expression.
Yes, each query block has its own namespace. An alias in an inner subquery does not conflict with one in the outer query.