pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedbetter way
2+ messages / 2 participants
[nested] [flat]
* better way
@ 2000-08-28 11:13 Sherwin Daganato <win@email.com.ph>
0 siblings, 1 reply; 2+ messages in thread
From: Sherwin Daganato @ 2000-08-28 11:13 UTC (permalink / raw)
To: pgsql-sql
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: better way
@ 2000-08-29 00:50 Renato De Giovanni <rdg@viafractal.com.br>
parent: Sherwin Daganato <win@email.com.ph>
0 siblings, 0 replies; 2+ messages in thread
From: Renato De Giovanni @ 2000-08-29 00:50 UTC (permalink / raw)
To: 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@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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-08-29 00:50 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-08-28 11:13 better way Sherwin Daganato <win@email.com.ph>
2000-08-29 00:50 ` Renato De Giovanni <rdg@viafractal.com.br>
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