SQL Aliases Statement
SQL Aliases are used to give temporary names to tables and columns. If users want the name to be more readable than the Aliases used.The Aliases only gives temporary names does not change in the original database.Aliases are usually preferred when a query includes more than one table.
Aliases statement Syntax :
The syntax of the Aliases statement is −
Alias Column Syntax -------------------- SELECT column-name AS alias-name FROM table-name; -------------------- -------------------- Alias Table Syntax ------------------- SELECT column-name(s) FROM table-name AS alias-name;
Aliases statement Example :
Consider the Customer table with the following records -
CustomerID | CustomerName | Age | Address | CustomerSalary | Gender |
---|---|---|---|---|---|
1 | Aarav | 28 | Udaipur | 28000 | M |
2 | Aarushi | 25 | Mumbai | 30000 | F |
3 | Reyansh | 28 | Chennai | 35000 | M |
4 | Aditi | 24 | Udaipur | 50000 | F |
5 | Sai | 30 | Mumbai | 27000 | M |
Alias for Columns Examples:- The following code is an example that will temporarily change the column name to "Name" :-
SELECT CustomerName AS Name FROM Customer;
The result for the respective sql query is as follows −
Name |
---|
Aarav |
Aarushi |
Reyansh |
Aditi |
Sai |
Alias for Tables Examples:- The following code is an example that will temporarily change the table name to C :-
SELECT CustomerName FROM Customer AS C;
The result for the respective sql query is as follows −
CustomerName |
---|
Aarav |
Aarushi |
Reyansh |
Aditi |
Sai |
Visit :
Discussion