×
☰ See All Chapters

Oracle Column Aliases

  1. SQL aliases are used to temporarily rename a table or a column heading. 

  2. SQL aliases are used to give a database table or a column in a table, a temporary name. 

  3. Basically aliases are created to make column names more readable. 

  4. Alias is used generally when 

    • The column names are big and not readable. 

    • Functions are use in a SELECT query. 

    • When there are more than two tables used in a SELECT query. 

SQL Alias Syntax for Columns

SELECT column_name AS alias_name

FROM table_name;

SQL Alias Syntax for Tables

SELECT column_name(s)

FROM table_name AS alias_name;

 

Example of Aliases in SQL Query for column names

oracle-using-column-aliases-0

If you execute the query below:

select FIRST_NAME as FN, LAST_NAME as LN from EMPLOYEE;

The result set will look like this:

oracle-using-column-aliases-1

Example of Alias in SQL Query for Tables

Consider the following two tables:

oracle-using-column-aliases-2

oracle-using-column-aliases-3

Below is the query to fetch data from both tables using SQL alias:

select e.EMPLOYEE_ID, e.FIRST_NAME, e.LAST_NAME, ec.COUNTRY

from EMPLOYEE e, EMPLOYEE_COUNTRY ec

where e.EMPLOYEE_ID = ec.EMPLOYEE_ID;

Result table look like:

 

All Chapters
Author