Re: SQL dealing with subquery - Mailing list pgsql-sql

From Rodrigo E. De León Plicet
Subject Re: SQL dealing with subquery
Date
Msg-id a55915760801151240w61aa3520g548eff734190061e@mail.gmail.com
Whole thread Raw
In response to SQL dealing with subquery  ("Bryan Emrys" <bryan.emrys@gmail.com>)
Responses Re: SQL dealing with subquery  (Bryan Emrys <bryan.emrys@gmail.com>)
List pgsql-sql
On Jan 15, 2008 1:04 PM, Bryan Emrys <bryan.emrys@gmail.com> wrote:
> In other words, in the sample above, I only want to return:
> 'Canada','Ireland',0
> 'Canada','Netherlands',5

Try (untested):

SELECT t2.*
FROM   (SELECT   payor       FROM     treaty_rates       WHERE    payee IN ('Netherlands', 'Ireland')       GROUP BY
payor      HAVING   MIN (rate) != MAX (rate)) t1      JOIN      treaty_rates t2 ON t1.payor = t2.payor
 
WHERE  t2.payee IN ('Netherlands', 'Ireland');


pgsql-sql by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Update PK Violation
Next
From: Gerardo Herzig
Date:
Subject: obtaining the query string inside a trigger