Home » SQL & PL/SQL » SQL & PL/SQL » alias
alias [message #178] Thu, 24 January 2002 04:40 Go to next message
Walt
Messages: 1
Registered: January 2002
Junior Member
What does a.ename, a. deptno,...refer to?

SELECT a.ename, a.sal, a.deptno, b.salavg
2 FROM emp a, (SELECT deptno, avg(sal) salavg
3 FROM emp
4 GROUP BY deptno) b
5 WHERE a.deptno = b.deptno
6 AND a.sal > b.salavg;

Thank you
Re: alias [message #181 is a reply to message #178] Thu, 24 January 2002 06:03 Go to previous messageGo to next message
GLK
Messages: 2
Registered: January 2002
Junior Member
Hi,
'A' IS A TABLE ALIAS. AS IN 'EMP A'
THE OTHER DATA SOURCE IS A SQL QUERY AND IS GIVEN THE ALIAS 'B' TO HELP DIFFERENTIATE WHICH COLUMNS ARE TAKEN FROM WHICH DATA SOURCE (TABLE OR QUERY).
IT IS GOOD PRACTICE TO HAVE TABLE ALIASES WHENEVER YOU ARE USING A JOIN (LIKE IN THE QUERY ABOVE)....Hope this helps you (sorry, had the caps locks on!)
Re: alias [message #186 is a reply to message #178] Thu, 24 January 2002 19:57 Go to previous messageGo to next message
pk
Messages: 12
Registered: September 2000
Junior Member
Instead of using tablename or table columnname u can do aliasing of the table or column to give a meaningful name.If your tablename or columnname is big and is repeated number of times then its a good practice to alias with a smaller name to make the code lean and thin and in turn which will be faster in execution.

Hope this will work for you !!
pk
Re: alias [message #200 is a reply to message #178] Mon, 28 January 2002 01:12 Go to previous messageGo to next message
Diwakar Bhandari
Messages: 7
Registered: January 2002
Junior Member
Alias basically serves two main pruposes :

1) Allowing the user to give more meaningful names to their columns ...Say like if u are doing (sal * 5) , U certainly won't like this to be displayed as column heading ...Instead if u use something like (sal * 5 ) as SalHike , it makes more sense .

2) suppose in an equi join query u are referring to a column which appears in both tables , then alias provides a way to distinguish which column is from which table ...

Like select e.ename , d.deptno from emp e , dept d where e.deptno = d.deptno ;

Hope this helps
Regards
Diwakar
Re: alias [message #1076 is a reply to message #178] Wed, 27 March 2002 20:03 Go to previous message
Nilesh
Messages: 16
Registered: November 1999
Junior Member
Your Comment :IT IS GOOD PRACTICE TO HAVE TABLE ALIASES WHENEVER YOU ARE USING A JOIN

My Question : Any pointer to actual advantage of using a table alias. Does it help in improving the query performance ?
Previous Topic: complex query question
Next Topic: downgrading data from oracle 8i to oracle 8.0.5
Goto Forum:
  


Current Time: Fri Apr 26 17:06:41 CDT 2024