X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A82D09DCA08 for ; Fri, 3 Feb 2006 09:21:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20152-10 for ; Fri, 3 Feb 2006 09:21:08 -0400 (AST) X-Greylist: delayed 00:16:31.846109 by SQLgrey- Received: from alimail.net (potatis.alimail.net [84.19.131.11]) by postgresql.org (Postfix) with ESMTP id 12EAE9DC878 for ; Fri, 3 Feb 2006 09:21:02 -0400 (AST) Received: from [192.168.1.10] ([84.19.128.181]) by alimail.net (alimail.net [10.1.8.71]) (MDaemon.PRO.v8.0.4.R) with ESMTP id md50000502117.msg for ; Fri, 03 Feb 2006 14:20:39 +0100 In-Reply-To: <72558D9A7573814BB4082A28843E03D402658B4E@intyodc01.uk.ioko365.com> References: <72558D9A7573814BB4082A28843E03D402658B4E@intyodc01.uk.ioko365.com> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <3F3A99C3-2368-4DD2-9396-2A2C23B14CF1@tele2.se> Cc: Content-Transfer-Encoding: 7bit From: Niklas Johansson Subject: Re: Help writing a piece of SQL Date: Fri, 3 Feb 2006 14:20:31 +0100 To: "Nigel Bishop" X-Mailer: Apple Mail (2.746.2) X-Spam-Processed: alimail.net, Fri, 03 Feb 2006 14:20:39 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 84.19.128.181 X-Return-Path: spot@tele2.se X-MDaemon-Deliver-To: pgsql-sql@postgresql.org Reply-To: spot@tele2.se X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.359 required=5 tests=[AWL=-0.120, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.359 X-Spam-Level: X-Archive-Number: 200602/35 X-Sequence-Number: 24045 On 3 feb 2006, at 14.06, Nigel Bishop wrote: > Thank you very much, that did the business This should generate the same plan as the previous query, but be a little bit more clean and easy to read: SELECT sendto FROM users t1 WHERE domain='rusty.com' AND username = COALESCE((SELECT username FROM users WHERE username='fred' and domain=t1.domain), username); Sincerely, Niklas Johansson