Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f4SCTCA92628 for ; Mon, 28 May 2001 08:29:12 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from gate.no9.cz ([194.228.119.34]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4N92iA56111 for ; Wed, 23 May 2001 05:02:45 -0400 (EDT) (envelope-from minca@no9.cz) Received: from mincak ([10.1.1.11]) by gate.no9.cz (8.9.3/8.9.3) with SMTP id JAA07479 for ; Wed, 23 May 2001 09:44:13 +0200 Message-ID: <006b01c0e367$dbbe6ac0$0b01010a@no9.cz> From: "Martin Smetak" To: Subject: Recursive select Date: Wed, 23 May 2001 11:07:56 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 X-Archive-Number: 200105/294 X-Sequence-Number: 3131 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 ?? 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]