Re: Help writing a piece of SQL

From: Niklas Johansson <spot(at)tele2(dot)se>
To: "Nigel Bishop" <Nigel(dot)Bishop(at)ioko(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help writing a piece of SQL
Date: 2006-02-03 13:20:31
Message-ID: 3F3A99C3-2368-4DD2-9396-2A2C23B14CF1@tele2.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message SunWuKung 2006-02-03 20:27:45 Re: regarding debugging?
Previous Message Nigel Bishop 2006-02-03 13:06:28 Re: Help writing a piece of SQL