Received: from jennifer.emc.com.ph ([208.232.224.2]) by hub.org (8.10.1/8.10.1) with ESMTP id e7SBBdL50499 for ; Mon, 28 Aug 2000 07:11:40 -0400 (EDT) Received: from fc.emc.com.ph (fc.emc.com.ph [208.232.224.197]) by jennifer.emc.com.ph (Postfix) with ESMTP id AEE94D740 for ; Mon, 28 Aug 2000 19:13:27 +0800 (PST) Message-id: Date: Mon, 28 Aug 2000 19:13:27 +0800 Subject: better way To: pgsql-sql@postgresql.org From: "Sherwin Daganato" MIME-Version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200008/311 Is there a better way to write this: SELECT a.oid_fld FROM for_payment a WHERE a.serial_fld <> 2 AND EXISTS (SELECT b.char_fld FROM for_payment b WHERE b.serial_fld = 2 AND b.char_fld = a.char_fld) Table for_payment +-------------+------------+-----------+ | serial_fld | char_fld | oid_fld | +-------------+------------+-----------+ | 1 | test1 | 456701 | | 2 | test1 | 456702 | | 3 | test1 | 456703 | | 4 | test2 | 456704 | | 5 | test3 | 456705 | +-------------+------------+-----------+ sample problem: Assuming that I pick 2 in serial_fld. How do I get the oid_fld of the rows with char_fld equal to the char_fld of 2? I should get these: +-----------+ | oid_fld | +-----------+ | 456701 | | 456702 | +-----------+ Thanks.