A column alias :- Renames a column heading
- Is useful with calculations
- AS keyword is mandatory between the column name and alias
- Requires double quotation marks if it contains spaces or special characters or if it is case-sensitive
Example :- postgres=# select ename, sal, comm as "commission" from emp;
ename | sal | commission
--------+---------+------------
SMITH | 800.00 |
ALLEN | 1600.00 | 300.00
WARD | 1250.00 | 500.00
JONES | 2975.00 |
MARTIN | 1250.00 | 1400.00
BLAKE | 2850.00 |
CLARK | 2450.00 |
SCOTT | 3000.00 |
In the previous post we have seen when we performed a mathematical operation the resultant column was labeled with ?Column? automatically... but here the same column has labeled as commission.
This is how we can name/rename the column name in SQL as per our requirement.