Monday, August 29, 2011

SQL ALIASES


SQL aliases can be used with database tables and with database table columns, depending on task you are performing. 

SQL column aliases are used to make the output of your SQL queries easy to read and more meaningful:


SELECT Employee, SUM(Hours) As SumHoursPerEmployee
FROM EmployeeHours
GROUP BY Employee

In the example above we created SQL alias SumHoursPerEmployee and the result of this SQL query will be the following: 

Employee
SumHoursPerEmployee
Scott Armstrong
25
Allan Babel
24
Tina Crown
27

Consider the following SQL statement, showing how to use SQL table aliases: 


SELECT Emp.Employee
FROM EmployeeHours AS Emp

Here is the result of the SQL expression above: 

Employee
Scott Armstrong
Allan Babel
Tina Crown

The SQL table aliases are very useful when you select data from multiple tables and when using joins. 

MORE BASIC SQL COMMANDS

No comments:

Post a Comment