TechnoLearnAcademy

TECHNOLEARN

SQL ALIASES

SQL ALIASES are used to provide a temporary name to a given table or column.
No physical changes are made to an existing table or column using aliases.
After executing the ALIASES query, the names of all tables and columns will return to their original form.
An alias is created with the AS keyword.

Syntax:

                 SELECT column1 as alias_column FROM tablename; 
Let’s understand the aliases statement with an example. For demonstration purposes, we will be using the table emp.
         Table Emp
COLUMN ALIASES

Example:

   Objective: In this example, we will be creating aliases for the HireDate column. Create an alias called JoiningDate for the                        HireDate column.
                      SELECT HireDate as JoiningDate from Tbl_Emp;
    Output:

Example:

   Objective:  It requires square brackets if the alias name contains spaces.        
                       SELECT HireDate AS [Joining Date] from Tbl_Emp;
    Output:
TABLE ALIAS

Example:

   Objective:  Assign the alias “c” to the table emp and retrieve all records from the IT department.
                       SELECT e.Firstname, e.Lastname, e.Salary, e.Department from Tbl_Emp AS e
                                                                             where e
.Department = ‘IT’;
    Output:

continue reading…….

Scroll to Top