DEV Community

wanglei
wanglei

Posted on

Aliases

SQL can rename a table or a column. The name is the alias of the table or the column. Aliases are created to improve the readability of table names or column names. In SQL, AS is used to create an alias.

Syntax
Column alias syntax

SELECT 
{ * | [column [ AS ] output_name, ...] }
[ FROM from_item [, ...] ]
[ WHERE condition ];
Enter fullscreen mode Exit fullscreen mode

Table alias syntax

SELECT column1, column2.... 
FROM table_name AS output_name 
WHERE [condition];
Enter fullscreen mode Exit fullscreen mode

Parameter Description
output_name

You may use the AS output_name clause to give an alias for an output column. The alias is used for displaying the output column. The name, value, and type keywords can be used as column aliases.

Examples
Use C to indicate the alias of the customer_t1 table to query data in the table.

openGauss=# SELECT c.c_first_name,c.amount FROM customer_t1 AS c;
 c_first_name | amount
--------------+--------
 Grace        |   1000
 Grace        |
              |
 Joes         |   2200
 James        |   5000
 Local        |   3000
 Lily         |   1000
 Lily         |   2000
(8 rows)
Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)