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

Table Alias

Function

Assign an alias to a table or a subquery result.

Syntax

SELECT attr_expr_list FROM table_reference [AS] alias;

Keywords

  • table_reference: Can be a table, view, or subquery.
  • AS: Can be used to connect table_reference and alias. Whether or not this keyword is added does not affect the command execution 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.

Examples

  • Assign the alias n to the table simple_table and use n.name to access the name field in simple_table.
    SELECT n.score FROM simple_table n WHERE n.name = "leilei";
  • Name the result of a subquery as m and use SELECT * FROM m to return all results from the subquery.
    SELECT * FROM (SELECT * FROM simple_table WHERE score > 90) AS m;