Loading, please wait...

Alias Syntax

How To Use Alias In SQL

 

Introduction:
In this article, you will learn, what alias is and how to use Alias in SQL.

SQL alias provides the facility to change the name of our table and column temporarily. It is an only temporary change for a fixed SQL statement. When we use this statement, our actual table name does not change in the database. One of the most important benefits of this statement is that if our table name is too long, we give a short name by alias or if. In our database, if two tables or columns are with the same name, we easily change these name with alias temporarily, otherwise, it generates the duplicate. It removes the duplicates also.

 

Here, we have two tables-

 

Employee Table

 

 

 

Query Table

 

 

 

Now, we used both tables, according to our condition.

 

  • First, we use table alias:

 

Syntax:

The syntax of table alias is as follows:

select column1, column2.... from table_name as alias_name where [condition];

 

 

Example:

Step 1: Now, we write our query for the table alias value.

select e.Id, e.Name, e.salary, e.Amount from employee as e query as q where e.Id = q.Id ;

 

 

 

Select and execute this query.

 

Step 2: The output of this query is:

 

 

 

  • Now, we use these records for Column Alias:

 

Syntax

The syntax of table alias is as follows:

select column_name as alias_name from table_name where [condition];

 

 

Example:

Step 1: Now, we write our query for table alias value.

select Id as Salary_Id, Name as Salary_Name from employee where Salary is not null;

 

 

 

Select and execute this query.

 

Step 2: The output of this query is:

 

 

 

Summary:
Thus, we learned that alias is used to change the name of the table and column temporarily. We also learnt its use in SQL.