Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Tutorial -> SQL Aliases

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 328
    Comment on it

    <-- Chapter 23: SQL Wildcards

    Chapter 24

    SQL Aliases


    SQL Aliases are used to rename a particular table name or column name in a temporary manner. In a SQL statement , any table or column name can be temporary change.

    SQL Syntax for Columns :-


    SELECT columnname AS columnaliasname
    FROM tablename;
    

    SQL Syntax for Tables :-


    SELECT columnname(s)
    FROM tablename AS tablealiasname;
    

    Lets see an examples from the below table "employees" :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000
    104 JKL E-104 CEO 12000
    105 MNO E-105 Software Developer 100000

    Alias TABLE COLUMN SQL syntax :-


    SELECT `name` AS [Employee Name], `designation` AS [Employee Designation]
    FROM `employees`
    

    Now run the above SQL query, we will see the output below :-


    Employee Name Employee Designation
    ABC Engineer
    DEF Doctor
    GHI Software Developer
    JKL CEO
    MNO Software Developer

    Now we can see here, columns "name" and "designation" are renamed temporary to Employee Name and Employee Designation.


    Alias TABLE SQL syntax :-


    SELECT `emp`.`name`,`emp`.`code` 
    FROM `employees` AS `emp`
    

    Now run the above SQL query, we will see the output below :-


    name code
    ABC E-101
    DEF E-102
    GHI E-103
    JKL E-104
    MNO E-105

    Now we can see here, table name "employee" is renamed temporary to "emp" .


    Chapter 25: SQL Joins -->

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: