Tutorials

SQL SELECT


SQL SELECT AS


We use SELECT AS in sql with a column name to assign that column a temporary name. 

Similary it can also be used to give a table a temporary name as well.

Syntax for SELECT AS

SELECT 
column1 AS user_defined_name1, 
column2 AS user_defined_name2,
.............................,
columnN AS user_defined_nameN
FROM table_name;

Example of SELECT AS

 

For demonstration we will take help of tih_Corses table:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online
 

We will temporarily assign name id to Course_ID, name to Course_Name and mode to Mode_of_Training.

For doing so we will write below query.

SELECT 
Course_ID AS id,
Course_Name AS name,
Professor,
Mode_of_Training AS mode
FROM tih_Course;

On executing the above query successfully, we will get following:

tih_Courses
id name Professor mode
001 .Net Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla Online
004 Basics of Computer Shweta  Online

In the above table, we can see that column name Course_ID, Course_Name, Mode_of_Training is replaced by their respected alias name.

Professor is unchanged as we haven't applied AS clause on this column.

 

Similarly you can apply SELECT AS on any table if there is need to change the column name temporarily.

 

ALIAS clause works similar to AS clause when applied with SELECT statement on columns.

 



Please Share this page
Views : 53
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!