Re: SELECT from multiple tables (not join though)

From: Derik Barclay <dbarclay(at)givex(dot)com>
To: Madison Kelly <linux(at)alteeve(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT from multiple tables (not join though)
Date: 2005-01-10 18:46:22
Message-ID: 200501101346.22957.dbarclay@givex.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

SELECT 'table1' AS source, file_name FROM file_info_1 WHERE
file_parent_dir='/'
UNION
SELECT 'table2' AS source, file_name FROM file_info_2 WHERE
file_parent_dir='/'
UNION
SELECT 'table3' AS source, file_name FROM file_info_3 WHERE
file_parent_dir='/' ORDER BY file_name;

On January 10, 2005 01:24 pm, Madison Kelly wrote:
> Bruno Wolff III wrote:
> > On Mon, Jan 10, 2005 at 12:47:53 -0500,
> >
> > Madison Kelly <linux(at)alteeve(dot)com> wrote:
> >>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.
> >
> > You can add a constant to the select list in each of the subselects
> > that indicates which table is being used.
>
> ^.^; Can you point me to docs that will help me learn how to do that?
> Thanks! Or rather, do you mean add a column to the table with an ID for
> the table that I select beside the file_name? If so, that is what I am
> planning to do if I can't find a smoother way to do it.
>
> Thanks!!
>
> Madison
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

--
Givex - http://www.givex.com/
Derik Barclay <dbarclay(at)givex(dot)com>, Systems Software Engineer
+1 416 350 9660
+1 416 250 9661 (fax)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message TJ O'Donnell 2005-01-10 18:48:29 Re: how to optimize my c-extension functions
Previous Message Brendan Jurd 2005-01-10 18:26:59 Re: Function for retreiving datatype