Re: SQL query...

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: SQL query...
Дата
Msg-id 20030219152812.GB17434@wolff.to
обсуждение исходный текст
Ответ на Re: SQL query...  ("Mario Weilguni" <mweilguni@sime.com>)
Список pgsql-general
On Wed, Feb 19, 2003 at 14:38:53 +0100,
  Mario Weilguni <mweilguni@sime.com> wrote:
> >if i have 5 tables and all of it has column X and i wanted to get unique
> >values in column X for all tables..
>
> >can i do it in one query?
>
> sure. this is one way to do this:
> select distinct foo.X from (
>   select X from table1
>   union
>   select X from table2
>   ....
>  ) as foo;
>
> if the values are unique within every table, then you might want to omit the
> surrounding select.

Union's will already only return unique values. So you don't need the outer
select distinct. You might get better performance by using union alls
with select distinct, since only one sort will be needed. For the case
where you know they are all unique, you can use union alls without the
select distinct.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: postgres error reporting
Следующее
От: "Mark Cave-Ayland"
Дата:
Сообщение: Re: 7.3.1 takes long time to vacuum table?