Received: from h00a024ee7419.ne.mediaone.net (h00a024ee7419.ne.mediaone.net [66.31.201.240]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4O3aUA89423 for ; Wed, 23 May 2001 23:36:30 -0400 (EDT) (envelope-from ron.peterson@yellowbank.com) Received: from yellowbank.com (IDENT:yrp001@h00a024ee7419.ne.mediaone.net [66.31.201.240]) by h00a024ee7419.ne.mediaone.net (8.11.1/8.11.1) with ESMTP id f4O3aAB28248; Wed, 23 May 2001 23:36:10 -0400 Message-ID: <3B0C81A9.64EC5005@yellowbank.com> Date: Wed, 23 May 2001 23:36:09 -0400 From: Ron Peterson Organization: Yellowbank X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.4.0 i586) X-Accept-Language: en MIME-Version: 1.0 To: Martin Smetak CC: pgsql-sql@postgresql.org Subject: Re: Recursive select References: <009301c0e368$589c0de0$0b01010a@no9.cz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200105/259 X-Sequence-Number: 3087 Don't drive yourself crazy ( like me ;). You'll have to write some procedural code - sorry. I believe IBM's DB/2 supports recursive queries as defined by SQL3. Oracle provide a couple of non SQL standard clauses (CONNECT BY, LEVELS) to provide similar funcionality. -Ron- GPG and other info at: http://www.yellowbank.com/ Martin Smetak 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 ?? > > 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] > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster