Hey, folks! In this article, we will be focusing on SQL SELECT AS statement in detail. So, let us begin!
What is SQL AS clause?
SQL AS clause enables the database administrator provide an alias name to the selected database. By alias, we mean to say, it provides an
alternate name to the table or column.
Thus, AS clause helps us protect the original column names from the external users of the database. Moreover, the alias name exists only during the execution of that particular query at runtime.
Let us have a look at the below syntax–
select column-name as alias-name from table-name; OR select column-name from table-name as alias-name;
Replacing the column name with the alias name helps us make the query even more efficient in size. Further, these changes are never permanent.
Let us now focus on implementing SQL SELECT AS statement through examples.
Implementing SQL SELECT AS command
create table Info(id integer, Cost integer); insert into Info(id, Cost) values(1, 100); insert into Info(id, Cost) values(2, 50); insert into Info(id, Cost) values(3, 65); insert into Info(id, Cost) values(4, 97); insert into Info(id, Cost) values(5, 12);
In the below example, we have created an alias name for the selected column — ‘Cost’ and displayed it using SQL SELECT statement as shown–
select Cost as Price, id from Info;
Now, let us try applying SQL AS command with table through the below example–
Select cost from Info as INFORMATION;
Here, we have provided an alternate name – ‘INFORMATION’ to the default table name – ‘Info’ using AS command.
The above screenshot displays the column however in the output, you will see the table name as INFORMATION. The above alias names work only for the execution of the particular query at runtime.
Moreover, the AS command does not erase the original column/table name, it just adds a temporary alternate name to it.
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.
For more such posts related to SQL Relational Database, do visit SQL database with JournalDev.
Till then, Happy Learning!!