Re: Help writing a piece of SQL

Поиск
Список
Период
Сортировка
От Niklas Johansson
Тема Re: Help writing a piece of SQL
Дата
Msg-id 9CA43D30-EF3A-49D7-A056-63480EF54027@tele2.se
обсуждение исходный текст
Ответ на Help writing a piece of SQL  ("Nigel Bishop" <Nigel.Bishop@ioko.com>)
Список 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 по дате отправления:

Предыдущее
От: "Nigel Bishop"
Дата:
Сообщение: Re: Help writing a piece of SQL
Следующее
От: "Nigel Bishop"
Дата:
Сообщение: Re: Help writing a piece of SQL