pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Renato De Giovanni <rdg@viafractal.com.br>
To: pgsql-sql@postgresql.org
Subject: Re: better way
Date: Mon, 28 Aug 2000 21:50:04 -0300
Message-ID: <39AB08BC.27CF43AE@viafractal.com.br> (raw)
References: <fc.000f567200676588000f567200676588.6768b1@fc.emc.com.ph>

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.





view thread (2+ messages)

Message-ID: <39AB08BC.27CF43AE@viafractal.com.br>
Permalink:  ../39AB08BC.27CF43AE@viafractal.com.br/
Also on:    postgresql.org/message-id/39AB08BC.27CF43AE@viafractal.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: rdg@viafractal.com.br
  Subject: Re: better way
  In-Reply-To: <39AB08BC.27CF43AE@viafractal.com.br>
  References: <fc.000f567200676588000f567200676588.6768b1@fc.emc.com.ph> <39AB08BC.27CF43AE@viafractal.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox