Re: SELECT from multiple tables (not join though)

From: Madison Kelly <linux(at)alteeve(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT from multiple tables (not join though)
Date: 2005-01-10 17:47:53
Message-ID: 41E2BFC9.6090605@alteeve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2005-01-10 18:00:47 Re: SELECT from multiple tables (not join though)
Previous Message Michael Fuhr 2005-01-10 17:47:50 Re: SELECT from multiple tables (not join though)