This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Oracle/OAS and the fly likes using aliases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "using aliases" Watch "using aliases" New topic
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: 133
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: 133
Hi Deepika,

you're right, and if you have such self joins you always need aliases.


John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using aliases