Updated on 2026-11-06 GMT+08:00

Column Alias

Function

Assigns an alias to a column.

Syntax

SELECT attr_expr [AS] alias, attr_expr [AS] alias, ... FROM table_reference;

Keywords

  • alias: Used to assign an alias to a field name in attr_expr.
  • AS: Whether this keyword is added does not affect the result.

Precautions

  • The table being queried must already exist. Otherwise, an error will occur.
  • The alias must be named before it is used. Otherwise, an error will occur. Additionally, you are advised to avoid duplicate names.

Example

First, obtain a result through a subquery SELECT name AS n FROM simple_table WHERE score > 90. The alias n assigned to name in the subquery can be directly used in the outer SELECT statement.

SELECT n FROM (SELECT name AS n FROM simple_table WHERE score > 90) m WHERE n = "xiaoming";