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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.