Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the use of Aliases in MySQL?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 377
    Comment on it

    In MySQL, aliases are used to give temporarily name to a table or a column. When we write a query we use Aliases to make column name more readable.

    Alias Syntax for Columns

    SELECT column_name AS alias_name
    FROM table_name;
    

    Alias Syntax for Tables

    SELECT column_name
    FROM table_name AS alias_name;
    

    We have a table "employee" as below:

        employee
    
        id  first_name               salary       country
        .......................................................
        1   John                     10000         Canada
        2   Chris                    20000         California
        3   Max                      30000         London
        4   Jenny                    25000         Canada
    

    Alias Example for Table Columns

    The below statement defines the alias for "first_name" column of the employee table:

    SELECT first_name AS EmplyeeName
    FROM employee;
    

    Result

        EmplyeeName
        ...............
        John           
        Chris          
        Max           
        Jenny         
    

    Alias Example for Tables

    The below statement creates the alias for the employee table:

    SELECT e.first_name, e.salary
    FROM employee AS e
    WHERE e.country ="Canada"**;
    

    Result**

        first_name               salary
        ................................
        John                     10000
        Jenny                    25000
    

    Hope this will help you :)

 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: