Alias is an associate name to the actual Table column name in SQL query. The alias also called user defined column name. The advantage is you can hide original column name and legibility of SQL query is good. Alias you can use small length name, so that you SQL query looks simple and easy to understand.
SELECT CUSTOMER_NAME as CNAME, CUSTOMER_ID as "CUST ID" , PRODUCT_ID as "AVG" FROM PRODUCT_TABLE WHERE PRODUCT_ID = '120'
Notes: The “CUST ID” has space and “AVG” is reserved word
3 Top rules to give alias
- ‘AS’ is optional-but if you miss the ‘,’ it will take column name as alias
- You need to give double quotes, when you have space in alias name
- If the alias name is reserved word, then you need to give double quotes
In SQL query you never need double quotes unless you use alias name with ‘spaces’ or reserved word
Read more on
- DB2 UDF sample function read now with awesome interview question
- Real idea Left outer JOIN you always need to code in DB2 read now
- 3 top rules to write alias instead of Table column name in SQL query