3 top rules to write alias instead of Table column name in SQL query

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

  1. ‘AS’ is optional-but if you miss the ‘,’ it will take column name as alias
  2.  You need to give double quotes, when you have space in alias name
  3.  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 | SQL | Functions

Also read

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.