Sponsors

Monday, June 28, 2010

What is SQL Alias? What are types of SQL Alias?

There are two types of aliases that are used most frequently in SQL command: which is column alias and table alias.

Why ALIAS? There is some reasons alias to be use when querying a SQL command.

- alias in a long query can make your query easier to read and understand
- alias table is use when using a same table in one query
- alias column is to identify the column naming when used together with aggregate functions, then the column can be understand easily

Syntax for Column Name Alias is :

SELECT [COLUMN NAME] AS COLUMN_ALIAS FROM [TABLE NAME]

Syntax for Table Name Alias is :

SELECT [COLUMN NAME] FROM [TABLE NAME] AS TABLE_ALIAS

Exmaple for Table Alias

select a.* from mytable as a;


Exmaple for Column Alias

select count(*) as total from mytable;

No comments:

Post a Comment