Re: better way

From: Renato De Giovanni <rdg(at)viafractal(dot)com(dot)br>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: better way
Date: 2000-08-29 00:50:04
Message-ID: 39AB08BC.27CF43AE@viafractal.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)viafractal(dot)com(dot)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.

In response to

  • better way at 2000-08-28 11:13:27 from Sherwin Daganato

Browse pgsql-sql by date

  From Date Subject
Next Message Renato De Giovanni 2000-08-29 01:12:42 Re: Can I get this all in one query?
Previous Message Tom Lane 2000-08-29 00:48:18 Re: pg_attribute_relid_attnam_index problem after log disk filled up