Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using aliases

 
Deepika Saxena
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John.
I guess this query is self joining Emp table.
Please correct me if i am wrong.
--Deepika
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepika,

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


John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic