X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 62228D1C4C7 for ; Mon, 21 Jul 2003 11:46:12 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 12135-05 for ; Mon, 21 Jul 2003 11:46:03 +0000 (GMT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id 02858D1C4CC for ; Mon, 21 Jul 2003 08:46:03 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) id 19eZ7F-0005Wd-0X; Mon, 21 Jul 2003 12:46:05 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id AEA741786A; Mon, 21 Jul 2003 12:46:04 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 2805E1785A; Mon, 21 Jul 2003 12:46:04 +0100 (BST) From: Richard Huxton To: Jo , pgsql-sql@postgresql.org Subject: Re: How to write this query! Date: Mon, 21 Jul 2003 12:46:02 +0100 User-Agent: KMail/1.5 References: <20030713163222.88233.qmail@web10305.mail.yahoo.com> In-Reply-To: <20030713163222.88233.qmail@web10305.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200307211246.02554.richardh@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/303 X-Sequence-Number: 14417 On Sunday 13 July 2003 17:32, Jo wrote: > These are my PostgreSQL tables: > > pid | name > 1 | A > 2 | B > 3 | C > 4 | D > 5 | E > > tid | pid 1 | pid 2 | pid 3 > 1 | 1 | 2 | 3 > > Bascially, I would like to write a query to list only > the names which their "pid" match those pids in the > other table. If anyone knows, pls help!! Jo - not sure how your message took this long to reach the list, but it doesn't look like someone has answered, so... SELECT DISTINCT a.name FROM table_a AS a, table_b as b WHERE a.pid=b.pid1 OR a.pid=b.pid2 OR a.pid=b.pid3; -- Richard Huxton Archonet Ltd