Received: from bugs.unl.edu.ar (bugs.unl.edu.ar [168.96.132.208]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4SF8MA80752 for ; Mon, 28 May 2001 11:08:25 -0400 (EDT) (envelope-from martin@bugs.unl.edu.ar) Received: by bugs.unl.edu.ar (Postfix, from userid 1004) id 300CD2AB3A; Mon, 28 May 2001 12:08:46 +0300 (GMT) Content-Type: text/plain; charset="iso-8859-2" From: =?iso-8859-2?q?Mart=EDn=20Marqu=E9s?= To: "Martin Smetak" Subject: Re: Recursive select Date: Mon, 28 May 2001 12:08:44 +0300 X-Mailer: KMail [version 1.2] References: <006b01c0e367$dbbe6ac0$0b01010a@no9.cz> In-Reply-To: <006b01c0e367$dbbe6ac0$0b01010a@no9.cz> Cc: MIME-Version: 1.0 Message-Id: <01052812084400.17901@bugs> Content-Transfer-Encoding: 8bit X-Archive-Number: 200105/298 X-Sequence-Number: 3139 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 -----------------------------------------------------------------