-
SQL tuning
Hello Guys,
I have the following SQL :
select c.cm_cod,par.cm_cod,c.cm_cod_p,c.cr#,c.branch#
from company c,company par
where (c.cm_cod_p=par.cm_cod ) ------for branches <> 1
and c.cm_cod_p=18516 -------this is the main
The output is
CM_COD CM_COD CM_COD_P CR# BRANCH#
---------- ---------- ---------- ---------- ----------
18514 18516 18516 13657 4
18515 18516 18516 13657 6
18518 18516 18516 13657 5
18517 18516 18516 13657 3
Where the company table is self referenced with the column cm_cod.
Can i get the same output in a single table reference(without referencing company table twice)(eg.company c and company par)
Thanks in advance
-
Code:
select cm_cod,cm_cod_p,cr#,branch#
from company
start with cm_cod_p=18516
connect by prior cm_cod = cm_cod_p
Cheers.
It is better to ask and appear ignorant, than to remain silent and remain ignorant.
Oracle OCP DBA 9i,
C++, Java developer
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|