SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable.
An alias only exists for the duration of that query.
An alias is created with the AS
keyword.
Actually, you can skip the AS
keyword and get the same result:
The AS
keyword is often used when two or more fields are concatenated into one.
To concatenate two fields use ||
.
Concatenate two fields and call them product
:
SELECT product_name || unit AS product
FROM products;
Run Example »
Note: In the result of the example above we are missing a space between product_name and unit. To add a space when concatenating, use || ' ' ||
.
Concatenate, with space:
SELECT product_name || ' ' || unit AS product
FROM products;
Run Example »
If you want your alias to contain one or more spaces, like "My Great Products
", surround your alias with double quotes.
Surround your alias with double quotes:
SELECT product_name AS "My Great Products"
FROM products;
Run Example »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!