Home »
SQL
SQL Alias
What is SQL alias? Here, we are going to learn how we can define aliases of table, column in SQL? What is the purposes of aliases and what is the advantages of SQL?
Submitted by Preeti Jain, on April 02, 2018
SQL Aliases
- Aliases means alternative name.
- We can define SQL aliases using 'as' clause.
- SQL aliases can be used to give a temporary name.
- Purpose of SQL aliases is to improve readability.
- We can implement SQL aliases for table or column.
Syntax for table:
SELECT column_name FROM table_name as alias_name;
Syntax for column:
SELECT column_name as alias_name
FROM table_name;
Example: Alias for column name:
Table records
Full_name
Anny Sharma
Ayesha Sharma
Preeti jain
Rahul jain
Query
mysql> SELECT full_name as name FROM emp;
Output
Name
Anny Sharma
Ayesha Sharma
Preeti jain
Rahul jain
Example: Alias for table name
Table
Id Full_name
3 Anny sharma
4 Ayesha jain
5 Preeti jain
6 Rahul jain
Query
mysql> SELECT * FROM emp as e where e.id = 4;
Output
Id Full_name
4 Ayesha jain