MySQL's set an alias (AS)

When using MySQL Query, when a long table name or perform some special query time, in order to facilitate operation or when the need to use the same table multiple times, you can specify an alias for a table, use the table alias instead of the original name.

The basic syntax for the table alias is:

<Table name> [the AS] <alias>

Wherein the meaning of each of the following clauses:

  • <表名>: The name of the data stored in the data table. ·
  • <别名>: Specifies the new name of the query table.
  • AS: The keyword is optional.


[Example 1] is tb_students_info stu alias table, SQL statements and input the execution result is shown below.

 

 Note: When a table alias, to ensure that the name does not conflict with other tables in the database.

When using a SELECT statement query results, MySQL will be displayed after each SELECT column specified output, in some cases, the column name will be displayed in a very long name or not intuitive, MySQL can specify the column aliases, replace field or expression .

The basic syntax for a column alias is:

<Column name> [the AS] <column alias>

Among them, the meaning of each clause syntax is as follows:

  • <列名>: The name for the fields defined in the table.
  • <列别名>: Field new name.
  • AS: The keyword is optional.


[Example 2] tb_students_info query tables for student_name alias name, age of alias student_age, SQL statements and input the execution result is shown below.

Note: The table alias is used only when the query is executed, does not show in the returned results, and after the column definition alias, is returned to the client display, the result field displays the alias for the field column.

Guess you like

Origin www.cnblogs.com/ccstu/p/12167421.html