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

From Frank D. Engel, Jr.
Subject Re: SELECT from multiple tables (not join though)
Date
Msg-id 5C5499F6-6339-11D9-8618-0050E410655F@fjrhome.net
Whole thread Raw
In response to Re: SELECT from multiple tables (not join though)  (Madison Kelly <linux@alteeve.com>)
Responses Re: SELECT from multiple tables (not join though)  (Madison Kelly <linux@alteeve.com>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SELECT file_name, 1 FROM file_info_1 WHERE file_parent_dir='/' UNION
SELECT file_name, 2 FROM file_info_2 WHERE file_parent_dir='/' UNION
SELECT file_name, 3 FROM file_info_3 WHERE file_parent_dir='/'
ORDER BY file_name;

The second column now shows which table it came from.  No need to mess
with adding fields, OIDs, etc...

On Jan 10, 2005, at 1:24 PM, Madison Kelly wrote:

> Bruno Wolff III wrote:
>> On Mon, Jan 10, 2005 at 12:47:53 -0500,
>>   Madison Kelly <linux@alteeve.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
>
>
- -----------------------------------------------------------
Frank D. Engel, Jr.  <fde101@fjrhome.net>

$ ln -s /usr/share/kjvbible /usr/manual
$ true | cat /usr/manual | grep "John 3:16"
John 3:16 For God so loved the world, that he gave his only begotten
Son, that whosoever believeth in him should not perish, but have
everlasting life.
$
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB4s/o7aqtWrR9cZoRAuYtAJ95XxbFAcfK5MBDU+sC4ktulxqfwwCfbIfM
mjQKofx230j5myapOSbGCAc=
=WEWW
-----END PGP SIGNATURE-----



___________________________________________________________
$0 Web Hosting with up to 120MB web space, 1000 MB Transfer
10 Personalized POP and Web E-mail Accounts, and much more.
Signup at www.doteasy.com


pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: SELECT from multiple tables (not join though)
Next
From: Michael Fuhr
Date:
Subject: Re: Function for retreiving datatype