As Clause Is Used in SQL For Operations, Usage with Practical Example

Summary: You will learn in this article, SQL AS keyword and Why as the clause is used in SQL, Database Management System. Let’s understand the SQL AS keyword.

How to used ‘AS’ clause in SQL ?

‘As’ clause is used for Rename operation. The AS clause is used to rename a column or table with an alias. Therefore, An alias only exists for the period or duration of the query.

Introduction of SQL AS Clause

SQL AS command is used to provide an alias to table or column names in the queries. during this means, we can increase the readability and understandability of the query and column headings within the result set.

If we aim to write more readable queries, then you can be using short and concise aliases for the tables and columns will be most helpful in this objective. Few queries can be very difficult or more complex and can contain a lot of joins, besides that incomprehensible table & column names create this issue additional difficult and inconvenient.

At this time, for such queries, code readability and quality offer an obvious profit benefit to make changes quickly by different developers. Furthermore, working with SQL queries that contain long and complicated columns and table names can lead to consuming additional or more energy.

Shortly, SQL AS keyword, in different words using aliases for the column names generates a temporary or short-lived name for the column headings and is shown within the result sets of the queries. This idea helps to generate more meaningful and clear column headings.


When you will used aliases for the tables can be most helpful when a query involved a table more than once.


Furthermore especially, this usage type is a good practice for the queries that involve SQL joining clauses. we’ll build some examples in light of this info.

Preparing The Data To Understand AS Keyword

As per the given below the following query, we will create two tables and we will populate some information or data. Also, you’ll be able to follow this article’s examples within the SQL Fiddle simply. SQL Fiddle is a free tool that allows us to practice and test the SQL queries online without the need for any database and installation.

First Step: Create Table

Table 1: Customer_InfoForDeal

Table 2: OrderPayment_InfoForDeal

2nd Step: Insert Records in Both Table

Table 1: Insert Records in Table Customer_InfoForDeal

Table 2: Insert Records in Table OrderPayment_InfoForDeal

Using The SQL AS keyword Giving Aliases To Columns

Therefore, we can give an alias to the column names to make them more readable and understandable also this alias doesn’t affect the original column name and it’s only valid until the execution of the query. Furthermore, In the given below following query, we will give FirstName alias to CustomerInfoDealList_FirstName and LastName alias to CustomerInfo_LastName.

Columns Aliases: as clause is used in SQL for

Columns Aliases Example

Using The SQL AS keyword Giving Aliases To Tables

When we will use a table more than once in a query, then we can shorten the table name through the SQL AS syntax. Therefore, in the following query, we will give Customer alias to Customer_InfoForDeal and CustomerOrders alias to OrderPayment_InfoForDeal.

Giving Table Aliense using SQL AS Keyword.jpg

as clause is used in SQL for Example

Therefore, as we can see in the above example that the table aliases have been placed after the FROM keyword so we didn’t have to retype these long table names another time anywhere in the query. After the SQL ON keyword, we tend to use the alias of the tables.

Thus, if we don’t use the aliases the query text will be as follows.

Table Aliases Example

AS Clause Related FAQS

What is purpose of the SQL AS clause?

The AS keyword in SQL is used to change the column name in the output or assign a name to a derived column.

Which clause is used to rename operations?

The AS command is used for rename operations, attributes in the relations in the from clause. result. Hence, SQL Server provides a way or method of renaming the attributes of a result relation.

Do you need to use AS in SQL?

In Standard SQL Server they’ll have an optional AS clause however it shouldn’t be used because it may give the impression that something is being renamed when it isn’t. Furthermore, in fact, it should be omitted to enforce the point that it’s a range variable.

Which is AS clause used for?

AS keyword is used in: DEFINE statements, to name a record-set that will later be referenced by another statement like SQL SELECT or FROM clause.

What is rename operation in SQL?

The RENAME operation in SQL is used to rename the output of a relation.
Sometimes it’s straightforward and appropriate to break a complicated sequence of operations and rename it as a relation with totally different names. The reasons to rename a relation can be several, such as –

  • We may want to save the result of a relational algebra expression as a relation in order that we are able to use it later.
  • Furthermore, We may want to join a relationship with itself, furthermore, in such type of case, it becomes too confusing to specify that one in all the tables we are talking regarding, in that case, we rename one of the tables & perform SQL server join operations on them.