Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Employee table SQL question

Re: Employee table SQL question

From: Garry M. Filimonov <garry_at_promstal.ru>
Date: 1997/07/14
Message-ID: <01bc8553$82df8e00$38925ac3@garry.promstal.ru>#1/1

Cleve Sharpe <cleve_at_cbcsf.org> wrote in article <01bc8e1e$7c46a960$339ff5cf_at_cbcsf1.boca.net>...
> Hello everyone:
>
> I have an EMPLOYEE table with the following columns:
> ID,
> NAME,
> LOGIN *,
> SUPERVISOR_ID **
>
> * LOGIN is the same as SELECT USER FROM DUAL (Oracle Login);
> ** Supervisor_ID is the foreign key to the EMPLOYEE.ID column.
>
> I need the simplest SQL statement or PL/SQL script to get the following:
>
> 1. The SUPERVISOR of the EMPLOYEE who is logged in

a)
select * from employee
 where id=(select supervisor_id from employee where login=user);

> 2. That SUPERVISOR's SUPERVISOR Until we get to the
> head of the company whose SUPERVISOR is himself.
>

a)
select * from employee where id=
(select to_number(substr(max(to_char(level,'999')||id),4))   from employee
  start with login=user connect by id = prior supervisor_id) ;
b)
select * from
(select distinct -level ignore_field, * from employee   start with login=user connect by id = prior supervisor_id)  where rownum=1
;

-- 
-----------
G'luck!
Garry
Received on Mon Jul 14 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US