Re: SELECT from multiple tables (not join though) - Mailing list pgsql-general

From Madison Kelly
Subject Re: SELECT from multiple tables (not join though)
Date
Msg-id 41E2BFC9.6090605@alteeve.com
Whole thread Raw
In response to Re: SELECT from multiple tables (not join though)  (John Sidney-Woollett <johnsw@wardbrook.com>)
Responses Re: SELECT from multiple tables (not join though)
Re: SELECT from multiple tables (not join though)
List pgsql-general
John Sidney-Woollett wrote:
> I hope I've read your question properly - I seem to be giving answers to
> un-asked questions lately! ;)
>
> How about...
>
> SELECT file_name from file_info_1 WHERE file_name='/'
> union
> SELECT file_name from file_info_2 WHERE file_parent_name='/'
> union
> SELECT file_name from file_info_3 WHERE file_parent_name='/'
> order by file_name;
>
> Does that do what you want?
>
> John Sidney-Woollett

That worked perfectly, though now I realize I have another problem that
is hopefully easy to get around. Here is my query (with the type fixed):

SELECT file_name FROM file_info_1 WHERE file_parent_dir='/' UNION SELECT
file_name FROM file_info_2 WHERE file_parent_dir='/' UNION SELECT
file_name FROM file_info_3 WHERE file_parent_dir='/' ORDER BY file_name;

The trick now is I need to know which table each result came from. I can
add another column and record the table number and SELECT that at the
same time but before I do I was wondering if I can do this more
efficiently or elegantly.

Thank you very much!

Madison

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: SELECT from multiple tables (not join though)
Next
From: Alvaro Herrera
Date:
Subject: Re: SELECT from multiple tables (not join though)