Re: Recursive Query
Date: 19 Mar 2003 09:58:26 -0800
Yes this looks like a homework doesn't it. A typical textbook problem :-) But this is from a project I'm currently working on for work.
I used the SQL:
select c1.customer_id, c1.customer_name, c1.primary_id,
--add the primary name recursively
(select customer_name from customer where customer_id=c1.primary_id) primary_name,
c1.primary_flag, c1.active_flag, c1.last_update_id, c1.last_update_date
from customer c1, customer c2
group by c1.customer_id
This solution worked for me. I don't know if this is just Sybase allowing me to do this or is it ANSI SQL legal. Anyway it works.
"Alan" <alan_at_erols.com> wrote in message news:<b57vdv$25sh1b$1_at_ID-114862.news.dfncis.de>...
> Why would we do your homework for you? Just send the professor's email
> address, and we'll submit the answer directly.
> "Ray" <rfelipe_at_earthlink.net> wrote in message
> > Hi,
> > I have a table with an Id that references itself recursively and need
> > help building the query.
> > Here's the table structure:
> > employee_id PRIMARY_KEY
> > employee_name
> > supervisor_id
> > The supervisor_id refers to the employee_id depending on who is the
> > employee
> > supervisor.
> > My resultset should look like:
> > employee_id - employee_name - SUPERVISOR_NAME (instead of Id)
> > Thanks,
> > -Ray
Received on Wed Mar 19 2003 - 18:58:26 CET