---
title: "Alias in SQL Query why you need it"
description: "Giving alias name is not only enough and you also need to know these three rules before you write your SQL query"
url: https://srinimf.com/2018/06/02/alias-is-an-optional-column/
date: 2018-06-02
modified: 2019-03-22
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2018/06/alias-in-sql-query.jpg?fit=1200%2C900&ssl=1
categories: ["SQL"]
tags: ["Db2 Tips", "SQL alias rules to give in SQL"]
type: post
lang: en
---

# Alias in SQL Query why you need it

Alias is an associate name to the actual-Table column name in SQL query. The alias also called user defined column name.

You can hide original column name with alias 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 on writing 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](https://srinimf.com/category/db2-2/)| [SQL](https://srinimf.com/?s=sql) | [Functions](https://srinimf.com/2018/04/01/sql-query-numeric-function-used-in-real-time-banking-project/)

**Also read**

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2018%2F06%2F02%2Falias-is-an-optional-column%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2018%2F06%2Falias-in-sql-query.jpg%3Ffit%3D1200%252C900%26ssl%3D1&description=Alias%20in%20SQL%20Query%20why%20you%20need%20it)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2018/06/02/alias-is-an-optional-column/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2018/06/02/alias-is-an-optional-column/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2018/06/02/alias-is-an-optional-column/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2018/06/02/alias-is-an-optional-column/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Alias%20in%20SQL%20Query%20why%20you%20need%20it&body=https%3A%2F%2Fsrinimf.com%2F2018%2F06%2F02%2Falias-is-an-optional-column%2F&share=email)
-

### Like this:

Like Loading…
