Providing Meaningful Names for Columns - SQL

Problem
You would like to change the names of the columns that are returned by your query so they are more readable and understandable. Consider this query that returns the salaries and commissions for each employee:

1 select sal,comm
2 from emp
What's "sal"? Is it short for "sale"? Is it someone's name? What's "comm"? Is it communication? You want the results to have more meaningful labels.

Solution
To change the names of your query results use the AS keyword in the form: original_name AS new_name. Some databases do not require AS, but all accept it:

1 select sal as salary, comm as commission
2 from emp
SALARY COMMISSION
------- ----------
800
1600 300
1250 500
2975
1250 1300
2850
2450
3000
5000
1500 0
1100
950
3000
1300

Discussion
Using the AS keyword to give new names to columns returned by your query is known as aliasing those columns. The new names that you give are known as aliases. Creating good aliases can go a long way toward making a query and its results understandable to others.

** If you want the Full Table detail. Refer the SQL Table in Label List. Or Click here to View the Table

0 Comments: