ప్రధాన కంటెంట్‌కు వెళ్లండి
eLearner.app
మాడ్యూల్ 2 · 4లో పాఠం 3కోర్సులో 7/57~6 min
మాడ్యూల్ పాఠాలు (3/4)

ASతో పేరు మార్చడం

By default, columns in the result have the same name as the source column. When you select an expression (a calculation, a concatenation, an aggregate) the default name may look ugly or unclear. With AS you assign an alias, that is, a name of your choice:

SQL
SELECT <colonna_o_espressione> AS <alias>
FROM   <tabella>;

The keyword AS is optional (salary salary_eur works too), but writing it makes the query more readable. If the alias contains spaces or significant uppercase letters, wrap it in double quotes: AS "Annual Salary".

Examples

SQL
-- Rinomina semplice (in inglese per convenzione):
SELECT first_name AS name,
       last_name  AS surname
FROM employees;

-- Alias su un'espressione calcolata:
SELECT first_name,
       last_name,
       salary * 13 AS annual_pay
FROM employees;

Try it

వ్యాయామం#sql.m2.l3.e1
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Extract each employee's last name and salary, renaming the columns to 'last' and 'salary_eur'.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

The keyword is AS: SELECT column AS new_name.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది

Review exercise

వ్యాయామం#sql.m2.l3.e2
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Extract first and last name concatenated into a single column called 'full_name'. Use the || operator to concatenate and put a space between the two.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

In PostgreSQL string concatenation is done with ||, and then the alias with AS.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది