Re: Help writing a piece of SQL

Поиск
Список
Период
Сортировка
От Nigel Bishop
Тема Re: Help writing a piece of SQL
Дата
Msg-id 72558D9A7573814BB4082A28843E03D402658B4E@intyodc01.uk.ioko365.com
обсуждение исходный текст
Ответ на Help writing a piece of SQL  ("Nigel Bishop" <Nigel.Bishop@ioko.com>)
Ответы Re: Help writing a piece of SQL
Список pgsql-sql
Niklas,

Thank you very much, that did the business

Cheers

Nigel Bishop

-----Original Message-----
From: Niklas Johansson [mailto:spot@tele2.se]
Sent: 03 February 2006 13:00
To: Nigel Bishop
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Help writing a piece of 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





Communications on or through ioko's computer systems may be monitored or recorded to secure effective system operation
andfor other lawful purposes. 

Unless otherwise agreed expressly in writing, this communication is to be treated as confidential and the information
init may not be used or disclosed except for the purpose for which it has been sent. If you have reason to believe that
youare not the intended recipient of this communication, please contact the sender immediately. No employee is
authorisedto conclude any binding agreement on behalf of ioko with another party by e-mail without prior express
writtenconfirmation. 

ioko365 Ltd.  VAT reg 656 2443 31. Reg no 3048367. All rights reserved.


В списке pgsql-sql по дате отправления:

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