Re: SELECT from multiple tables (not join though)

Поиск
Список
Период
Сортировка
От Janning Vygen
Тема Re: SELECT from multiple tables (not join though)
Дата
Msg-id 200501101842.57790.vygen@gmx.de
обсуждение исходный текст
Ответ на SELECT from multiple tables (not join though)  (Madison Kelly <linux@alteeve.com>)
Список pgsql-general
Am Montag, 10. Januar 2005 18:22 schrieb Madison Kelly:
> Hi all,
>
>    I have another question, I hope it isn't too basic. ^.^
>
>    I want to do a select from multiple tables but not join them. What I
> am trying to do is something like this (though this doesn't work as I
> need):
>
> SELECT a.file_name, b.file_name, c.file_name FROM file_info_1 a,
> file_info_2 b, file_info_3 c WHERE a.file_name='/' AND
> b.file_parent_dir='/' AND c.file_parent_dir='/';
>
>    That returns every combination of the results from the three tables
> which is a huge number. What I need is to return all of the matches in
> all of the tables in a single column. Once I have all the matches in one
> column the next trick is to sort the combined results (any tips there?).

you want something like this

SELECT a.file_name
FROM file_info_1 a
WHERE a.file_name='/'

UNION

SELECT b.file_name
FROM file_info_2 b
WHERE b.file_name='/'

UNION

SELECT c.file_name
FROM file_info_3 c
WHERE c.file_name='/'

ORDER BY 1;

for further documentation visit

     http://www.postgresql.org/docs/7.4/interactive/sql-select.html

or your local postgresql documentation.

kind regards,
janning


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

Предыдущее
От: John Sidney-Woollett
Дата:
Сообщение: Re: SELECT from multiple tables (not join though)
Следующее
От: "Frank D. Engel, Jr."
Дата:
Сообщение: Re: SELECT from multiple tables (not join though)