Received: from www-uk-05.digiserve.com ([195.172.23.63]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f27Lpvx10021 for ; Wed, 7 Mar 2001 16:51:57 -0500 (EST) (envelope-from dev@archonet.com) Received: from mainbox.archonet.com (mwynhau.demon.co.uk [193.237.186.96]) by www-uk-05.digiserve.com (8.9.1/8.9.1) with ESMTP id VAA15382; Wed, 7 Mar 2001 21:52:59 GMT Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id B8F712A479; Wed, 7 Mar 2001 21:49:16 +0000 (GMT) From: dev@archonet.com Date: Wed, 07 Mar 2001 21:49:14 GMT Message-ID: <20010307.21491400@client.archonet.com> Subject: Re: work on rows To: Rachel Coin Cc: Reply-To: dev@archonet.com In-Reply-To: <00b701c0a739$c8170460$6101a8c0@spidinfo.com> References: <00b701c0a739$c8170460$6101a8c0@spidinfo.com> X-Mailer: Mozilla/3.0 (compatible; StarOffice/5.2;Linux) X-Priority: 3 (Normal) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.postgresql.org id f27Lpwx10026 X-Archive-Number: 200103/159 X-Sequence-Number: 1812 Author: Rachel Coin I have a problem with a sql query.I have two tables : the first contains categories and the second subcategories. What kind of select may I use to get something like Yahoo! categories ( each "main" category gets *at most* three sub-categories.. Do you mean something like the following? (PS - please don't post HTML to mailing lists) richardh=> select * from cats; c --- A B (2 rows) richardh=> select * from subcats; c | s ---+---- A | a1 A | a2 A | a3 A | a4 (4 rows) richardh=> select cats.c,subcats.s from cats,subcats where cats.c=subcats.c; c | s ---+---- A | a1 A | a2 A | a3 A | a4 (4 rows) richardh=> select cats.c,subcats.s from cats,subcats where cats.c=subcats.c and subcats.s in (select s from subcats where subcats.c=cats.c limit 2); c | s ---+---- A | a1 A | a2 (2rows) - Richard Huxton