Received: from rush.u-netsys.com.br (rush.u-netsys.com.br [200.192.48.10]) by hub.org (8.10.1/8.10.1) with SMTP id e7T0xNC80530 for ; Mon, 28 Aug 2000 20:59:27 -0400 (EDT) Received: (qmail 10378 invoked from network); 29 Aug 2000 00:40:59 -0000 Received: from ppp07-pm3.u-netsys.com.br (HELO viafractal.com.br) (200.192.49.136) by rush.u-netsys.com.br with SMTP; 29 Aug 2000 00:40:59 -0000 Message-ID: <39AB08BC.27CF43AE@viafractal.com.br> Date: Mon, 28 Aug 2000 21:50:04 -0300 From: Renato De Giovanni X-Mailer: Mozilla 4.72 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: better way References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200008/314 Didn't test this, but I think it should also work: SELECT a.oid_fld FROM for_payment a, for_payment b WHERE b.serial_fld = 2 AND b.char_fld = a.char_fld AND a.serial_fld <> 2 -- Renato Sao Paulo - SP - Brasil rdg@viafractal.com.br > 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.