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

SQL dealing with subquery comparison

From: "Bryan Emrys" <bryan(dot)emrys(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: SQL dealing with subquery comparison
Date: 2008-01-15 19:02:56
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Hi all,
I'm having a conceptual problem with a subquery here - any help would be

I have a table treaty_rates with columns payor, payee, rate where payor and
payee are countries.
Sample set:

There is no certainty  that the same payees exist for each payor (i.e. not
all countries have treaties with other all other countries)

I want to select all rows where the payee is in some array (e.g, in
('Netherlands','Ireland')) and the rate is not the same

In other words, in the sample above, I only want to return:

The initial query to limit the rows to the specified payees is obvious, but
I can't get my mind around how to compare each set of rows where the payor
is the same country. Running select payor, payee, rate where payee in
('Netherlands','Ireland') will return 132 rows (66 pairs).

Any suggestions on how to compare the pairs would be appreciated. (Obviously
I could also run into someone asking me for more than 2 payees and asking
for the combination payor/payee with the lowest rate for each individual



pgsql-sql by date

Next:From: Joost KraaijeveldDate: 2008-01-15 19:42:31
Subject: Re: Is DATETIME an ANSI-SQL type?
Previous:From: Bryan EmrysDate: 2008-01-15 18:04:29
Subject: SQL dealing with subquery

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