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 12:59:46 |
Message-ID: | 9CA43D30-EF3A-49D7-A056-63480EF54027@tele2.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 3 feb 2006, at 11.43, Nigel Bishop wrote:
> The query will have the username and domain passed in as variables.
> If the username and domain exist then return the sendto
> The bit I’m struggling with is if the username doesn’t exist then
> return the sendto where the domain exists
>
> e.g. username=fred (this doesn’t exist) and domain=rusty.com then
> returnrusty(at)rabbit(dot)com, matilda(dot)clematis(at)rabbit(dot)com,
> stoat(dot)griffin(at)rabbit(dot)com
I think this could do the trick for you:
SELECT sendto FROM users t1
WHERE domain='rusty.com' AND (username='fred') = EXISTS(SELECT 1 FROM
users t2 WHERE username='fred' and domain=t1.domain);
Sincerely,
Niklas Johansson
From | Date | Subject | |
---|---|---|---|
Next Message | Nigel Bishop | 2006-02-03 13:06:28 | Re: Help writing a piece of SQL |
Previous Message | Nigel Bishop | 2006-02-03 11:10:13 | Re: Help writing a piece of SQL |