Skip site navigation (1) Skip section navigation (2)

better way

From: "Sherwin Daganato" <win(at)email(dot)com(dot)ph>
To: pgsql-sql(at)postgresql(dot)org
Subject: better way
Date: 2000-08-28 11:13:27
Message-ID: fc.000f567200676588000f567200676588.6768b1@fc.emc.com.ph (view raw or flat)
Thread:
Lists: 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.




Responses

pgsql-sql by date

Next:From: Christopher SawtellDate: 2000-08-28 11:33:51
Subject: Re: Tutorial
Previous:From: Andreas TilleDate: 2000-08-28 09:53:17
Subject: Re: Argument variables for select

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group