| Author |
using aliases
|
Deepika Saxena
Ranch Hand
Joined: Jul 05, 2009
Posts: 59
|
|
Hi,
we will use table aliases in queries, if we have very long or complex table names or column names. are aliases only meant for this purpose? are there any other advantages using aliases?
Please let me know.
Thanks.
--Deepika
|
 |
John Bengler
Ranch Hand
Joined: Feb 12, 2009
Posts: 132
|
|
Hi Deepika,
one other purpose for table aliases is when you have a table twice in your select, then the use of aliases is mandatory.
E.g. if you know the table emp from the scott/tiger-scheme:
TABLE EMP
(EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(2));
If you want to select the employee names and the name of their manager:
select e1.ename,e2.ename from empe1,emp e2 where e1.mgr = e2.empno;
John
|
 |
Deepika Saxena
Ranch Hand
Joined: Jul 05, 2009
Posts: 59
|
|
Thanks John.
I guess this query is self joining Emp table.
Please correct me if i am wrong.
--Deepika
|
 |
John Bengler
Ranch Hand
Joined: Feb 12, 2009
Posts: 132
|
|
Hi Deepika,
you're right, and if you have such self joins you always need aliases.
John
|
 |
 |
|
|
subject: using aliases
|
|
|