In this tutorial, we will learn what is an alias and how to use ALIAS in SQL.
SELECT
statement.SELECT column AS AliasName
FROM tableName;
SELECT column1,column2,... columnN
FROM tableName as AliasName;
Let us consider this table "Employee" for records.
Table Name: Employee
ID | EmpName | FlatNo | City | Country | Gender | Salary |
1 | Shankar | A - 255 | Delhi | India | male | 25000 |
2 | Sourabh | A - 3 | Delhi | India | male | 30000 |
3 | Ranvijay | B - 526 | Mumbai | India | male | 15000 |
4 | Kapil | F - 255 | Noida | India | male | 25000 |
5 | Shalini | E - 205 | Jaipur | India | female | 18000 |
6 | Rakesh | J - 295 | Faridabad | India | male | 23000 |
7 | Akshay | A - 2055 | Mumbai | India | male | 21000 |
8 | Sarah | A - 55 | New York | US | female | 76000 |
9 | Rocky | A - 2505 | Noida | India | male | 28000 |
For creating Alias of the single or multiple columns, a query will be:
SELECT ID AS EmpID, EmpName AS Name
FROM Employee;
ID | Name |
1 | Shankar |
2 | Sourabh |
3 | Ranvijay |
4 | Kapil |
5 | Shalini |
6 | Rakesh |
7 | Akshay |
8 | Sarah |
9 | Rocky |
For creating Alias of the single or multiple columns, and alias contains space. Then you use a square bracket or double quotation marks, a query will be:
SELECT ID, EmpName AS [Employee Name]
FROM Employee;
SELECT ID, EmpName AS 'Employee Name'
FROM Employee;
ID | Name |
1 | Shankar |
2 | Sourabh |
3 | Ranvijay |
4 | Kapil |
5 | Shalini |
6 | Rakesh |
7 | Akshay |
8 | Sarah |
9 | Rocky |
For creating Alias for a table, a query will be:
SELECT *
FROM Employee as Emp;
ID | EmpName | FlatNo | City | Country | Gender | Salary |
1 | Shankar | A - 255 | Delhi | India | male | 25000 |
2 | Sourabh | A - 3 | Delhi | India | male | 30000 |
3 | Ranvijay | B - 526 | Mumbai | India | male | 15000 |
4 | Kapil | F - 255 | Noida | India | male | 25000 |
5 | Shalini | E - 205 | Jaipur | India | female | 18000 |
6 | Rakesh | J - 295 | Faridabad | India | male | 23000 |
7 | Akshay | A - 2055 | Mumbai | India | male | 21000 |
8 | Sarah | A - 55 | New York | US | female | 76000 |
9 | Rocky | A - 2505 | Noida | India | male | 28000 |