Re: Combining queries

Поиск
Список
Период
Сортировка
От Lew
Тема Re: Combining queries
Дата
Msg-id ijrp4k$odp$1@news.albasani.net
обсуждение исходный текст
Ответ на Re: Combining queries  (Thomas Kellerer <spam_eater@gmx.net>)
Ответы Re: Combining queries  (Mark Kelly <pgsql@wastedtimes.net>)
Список pgsql-novice
Mark Kelly wrote:
> If I have two queries:
>
> SELECT pub_id as id, email FROM publication WHERE email_accepted = TRUE;
>
> and
>
> SELECT contact_id as id, email FROM person WHERE email_accepted = TRUE;
>
> is there any way I could combine these into a single query? I'd like to be
> able to create a view of all email-able entities in the system.

Sean Davis wrote:
> Take a look at sql UNION--this is not postgresql specific.

Thomas Kellerer wrote:
> More precisely: UNION ALL to avoid the redundant step that tries to eliminate
> duplicates

One may eliminate the redundant test of a truth value against a truth value.

SELECT pub_id as id, email FROM publication WHERE email_accepted
UNION ALL
SELECT contact_id as id, email FROM person WHERE email_accepted ;

One trusts that the result columns in the two tables have compatible types.

I am curious how you interpret the "id" result in that query.

--
Lew
Honi soit qui mal y pense.

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

Предыдущее
От: "Jean-Yves F. Barbier"
Дата:
Сообщение: replication
Следующее
От: Mark Kelly
Дата:
Сообщение: Re: Combining queries