Re: Help writing a piece of SQL - Mailing list pgsql-sql

From Niklas Johansson
Subject Re: Help writing a piece of SQL
Date
Msg-id 9CA43D30-EF3A-49D7-A056-63480EF54027@tele2.se
Whole thread Raw
In response to Help writing a piece of SQL  ("Nigel Bishop" <Nigel.Bishop@ioko.com>)
List 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@rabbit.com, matilda.clematis@rabbit.com,
> stoat.griffin@rabbit.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





pgsql-sql by date:

Previous
From: "Nigel Bishop"
Date:
Subject: Re: Help writing a piece of SQL
Next
From: "Nigel Bishop"
Date:
Subject: Re: Help writing a piece of SQL