pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martín Marqués <martin@bugs.unl.edu.ar>
To: Martin Smetak <minca@no9.cz>
Cc: pgsql-sql@postgresql.org
Subject: Re: Recursive select
Date: Mon, 28 May 2001 12:08:44 +0300
Message-ID: <01052812084400.17901@bugs> (raw)
In-Reply-To: <006b01c0e367$dbbe6ac0$0b01010a@no9.cz>
References: <006b01c0e367$dbbe6ac0$0b01010a@no9.cz>

On Mié 23 May 2001 12:07, you wrote:
> Hi all!
>
> Anyone know if it's possible to make a recursive select from a table ?
> My problem: I got a table of "some categories" which all points to its
> parrent one(tree)...shown below. And I want to select all names of
> parrent categories of one child, lets say "fast[4]". Now I'm solving that
> with
> many SQL queries like : "SELECT main_id FROM cat WHERE id=4;"....but I
> would like to optimize this.
>
> Anyone can help or point me to a way ??

Sub-selects maybe?

SELECT main_id FROM cat WHERE id=(SELECT ID FROM cat WHERE name=crash)

Could this be what yo want?

Saludos.... :-)

> Thanks a lot,Minca
>
> Table : CAT
> ID        |        Main_id        |    Name
> =========================
> 1                    0                    Car
> 2                    1                    Crash
> 3                    1                    Wash
> 4                    3                    Fast
> 5                    1                    Second_hand
> 6                    0                    House
> 7                    3                    Slow
> ....etc
>
> *(root)[0]
> -Car[1]
>         -Crash[2]
>         -Wash[3]
>             -Fast[4]
>             -Slow[7]
>         -Second hand[5]
> -House[6]


-- 
Cualquiera administra un NT.
Ese es el problema, que cualquiera administre.
-----------------------------------------------------------------
Martin Marques                  |        mmarques@unl.edu.ar
Programador, Administrador      |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------



view thread (11+ messages)  latest in thread

Message-ID: <01052812084400.17901@bugs>
Permalink:  ../01052812084400.17901@bugs/
Also on:    postgresql.org/message-id/01052812084400.17901@bugs

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: martin@bugs.unl.edu.ar, minca@no9.cz
  Subject: Re: Recursive select
  In-Reply-To: <01052812084400.17901@bugs>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox