Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur.
SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
SQL aliases are used to give a temporary name to tables or columns in table. It is exist only duration of that query in perform. Alias are used to provide a easier name to table or column of table. An alias is create with use of ‘AS’ keyword.
Syntax :
Alias for column-
SELECT column_name AS alias_name FROM table_name;
We can also create alias for multiple column in a table.
SELECT column1 AS alias1, column2 AS alias2 ,… FROM table_name ;
Alias for Table-
SELECT colum1,column2,… FROM table_name AS alias_name ;
Example :
Lets have a table ‘Customer’,
Follow the statement is used alias for table column ‘cust_name’ as ‘name’ and ‘city’ as ‘c’ .
select cust_name as name, city as c from Customer;
The following SQL statement is using alias for a table ‘Customer’ as ‘cust’.
select cust.cust_name,cust.city,cust.customer_id from Customer as cust;
We can also provide aliases to retrieve record from more than one table at a time like below.
select cust.cust_name,cust.city,cust.customer_id, sale.salesman_id, sale.name
from Customer as cust,Salesman as sale where cust.salesman_id=sale.salesman_id;
We can also provide single alias for two or more columns in a table at a time. In the following statement a alias ‘name’ for column name ‘cust_name’ and ‘city’ in ‘Customer’ table.
select customer_id, cust_name+','+city as name from Customer;
To give space between alias name use [alias name] in SQL statement.
select customer_id, cust_name+' , '+city as [name address] from Customer;
In the following statement select a record where customer_id=3007(Brad Davis). By using ‘Customer’ and ‘Salesman’ table and give the alias name as ‘cust’ and ‘sale’ respectively.
select cust.customer_id, cust.cust_name,sale.salesman_id,sale.name
from Customer as cust, Salesman as sale
where cust.cust_name='Brad Davis' AND cust.salesman_id=sale.salesman_id;
Liked By
Write Answer
What is an ALIAS command in SQL Server, where apply alias in the database command?
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Ashutosh Kumar Verma
24-Sep-2021SQL Aliases :
SQL aliases are used to give a temporary name to tables or columns in table. It is exist only duration of that query in perform. Alias are used to provide a easier name to table or column of table. An alias is create with use of ‘AS’ keyword.
Syntax :
Alias for column-
We can also create alias for multiple column in a table.
Alias for Table-
Example :
Lets have a table ‘Customer’,
Follow the statement is used alias for table column ‘cust_name’ as ‘name’ and ‘city’ as ‘c’ .
The following SQL statement is using alias for a table ‘Customer’ as ‘cust’.
We can also provide aliases to retrieve record from more than one table at a time like below.
We can also provide single alias for two or more columns in a table at a time. In the following statement a alias ‘name’ for column name ‘cust_name’ and ‘city’ in ‘Customer’ table.
To give space between alias name use [alias name] in SQL statement.
In the following statement select a record where customer_id=3007(Brad Davis). By using ‘Customer’ and ‘Salesman’ table and give the alias name as ‘cust’ and ‘sale’ respectively.