Global GuideLine Home HTML Tutorial JavaScript Tutorial SQL Tutorial CSS Tutorial SEO Tutorial XML Tutorial XSLT Tutorial Articles Tutorial Interview Questions and Answers Guide Jobs GuideLine Bookmark With Google Bookmark With Yahoo Bookmark With FaceBook Bookmark With Live Follow @GlobalGuideLine on Twitter Bookmark Global GuideLine
SQL Alias Tables, SQL Tutorial, Global Guide Line Technology.
Bookmark this webpage. Bookmark: SQL Alias Tables, SQL Tutorial Global Guideline is UNITED STATES's favorite website

      Home                    

Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Cerate Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Alias Tables.


     Back             Next     




Now we focus here in SQL Tutorial on the use of aliases of SQL tables. There are two types of aliases that are used most frequently: column alias and table alias.

In short, column aliases exist to help organizing output. In the previous example, whenever we see total salary, it is listed as SUM(Salary). While this is comprehensible, we can envision cases where the column heading can be complicated (especially if it involves several arithmetic operations). Using a column alias would greatly make the output much more readable.

The second type of alias is the table alias. This is accomplished by putting an alias directly after the table name in the FROM clause. This is convenient when you want to obtain information from two separate tables (the technical term is 'perform joins'). The advantage of using a table alias when doing joins is readily apparent when we talk about joins.

Before we get into joins, though, let's look at the syntax for both the column and table aliases:


Syntax for SQL Alias Tables

SELECT "table_alias"."column_name1" "column_alias"
FROM "table_name" "table_alias"

Briefly, both types of aliases are placed directly after the item they alias for, separate by a white space. We again use our table of Employees.

Table Employees_Salary

FirstName Month Salary
Austin January 1000$
Creston January 1000$
Kate January 1000$
Angela January 1900$
Bobbi January 1000$
Cute January 1000$
Austin February 1100$
Creston February 1100$
Kate February 1100$
Angela February 1000$
Bobbi February 1200$
Cute February 1300$

We use the same example as that in the SQL GROUP BY section of our SQL Tutorial, except that we have put in both the column alias and the table alias:

Example of SQL Alias Tables

SELECT empSal.Month Month_Groupd, SUM(empSal.Salary) "Total Salary of Month"
FROM Employees_Salary empSal
GROUP BY empSal.Month

Result:

Month_Groupd Total Salary of Month
January 6900$
January 6800$

Important note is that difference in the result: the column titles are now different from the original stored in database. That is the result of using the column alias. Notice that instead of the somewhat hidden "Sum(Salary)", we now have "Total Salary of Month", which is much more understandable, as the column header. The advantage of using an SQL table alias is not apparent in this example. However, we will learn more about the table alias in next SQL Tutorial sections while using the complex kind of joins.


     Back             Next     
 
In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code:

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright © 2005-2006 www.globalguideline.com All rights reserved. Join Global Guide Line community. 793 visitors are online now