Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 76A1D2E0263 for ; Tue, 15 Jan 2008 16:40:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 55170-07 for ; Tue, 15 Jan 2008 16:40:10 -0400 (AST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.248]) by postgresql.org (Postfix) with ESMTP id 101422E0255 for ; Tue, 15 Jan 2008 16:40:13 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c36so594762ana.33 for ; Tue, 15 Jan 2008 12:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=WG432onTqW/OPb6hOmJHa6fvT63I79AyFif0jT+WoiU=; b=dsWyDiZvCxBBxvDwacFaQnq2IYmtryxkCJVLCzYwEGsV6R7Zt36eTF8MruSfzZT/J0zb4eXk0o9lENgphP+/9IcH60gD4fo7VGSNy1AHAIOzZGNmdQBjZ2InrKwZLFXwpa1J4MjwsEmfBVja9BVihZKtgdNfXRB/Dn/7V/Zcaa8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JsGqpqxhiwvoIZguQAEAP2/9QmhSJ+BAW7MP2g6HR8IQnrDoqIXdW13FcHXUx7ex4we70Vwy1HxEoEeTLVm+HsC7nUpebSYMYmSt0YtqS7XPFNqTf3LR1A8kmqfibJH/rkyX9HApL1zWQEIhZdd+PVS685Ia/Uv0848byj7RtIk= Received: by 10.100.253.12 with SMTP id a12mr17710237ani.43.1200429613237; Tue, 15 Jan 2008 12:40:13 -0800 (PST) Received: by 10.100.34.6 with HTTP; Tue, 15 Jan 2008 12:40:13 -0800 (PST) Message-ID: Date: Tue, 15 Jan 2008 15:40:13 -0500 From: "=?UTF-8?Q?Rodrigo_E._De_Le=C3=B3n_Plicet?=" To: "Bryan Emrys" Subject: Re: SQL dealing with subquery Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/136 X-Sequence-Number: 29989 On Jan 15, 2008 1:04 PM, Bryan Emrys 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');