sql alias

SQL Advance



SQL Alias

  • You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names. 
    An alias name could be anything, but usually it is short.

  • SQL Alias Syntax for Tables

    SELECT column_name(s)
    FROM table_name
    AS alias_name

  • SQL Alias Syntax for Columns

    SELECT column_name AS alias_name
    FROM table_name

  • SQL Alias EXAMPLES :

    we have a table called “emp” and another table called “emp_dept”. We will give the table aliases of “e” and “ed” respectively. 
    Now we want to list all the orders that “Raj Kiran” is responsible for. 
    We use the following SELECT statement: 

    SELECT ed.EID, e.Name2, e.Name1
    FROM emp AS e,
    emp_dept AS ed
    WHERE e.Name2=’Kiran’ AND e.Name1=’Raj’

    The same SELECT statement without aliases: 

    SELECT emp_dept.EID,emp.Name2, emp.Name1
    FROM emp, emp_dept
    WHERE e.Name2=’Kiran’ AND e.Name1=’Raj’

    you’ll see from the two SELECT statements above; aliases can make queries easier to both write and to read. 


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s