Re: SELECT from multiple tables (not join though)

From: "Frank D(dot) Engel, Jr(dot)" <fde101(at)fjrhome(dot)net>
To: pgsql general list <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT from multiple tables (not join though)
Date: 2005-01-10 18:56:39
Message-ID: 5C5499F6-6339-11D9-8618-0050E410655F@fjrhome.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(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
>
>
- -----------------------------------------------------------
Frank D. Engel, Jr. <fde101(at)fjrhome(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2005-01-10 19:07:21 Re: SELECT from multiple tables (not join though)
Previous Message TJ O'Donnell 2005-01-10 18:48:29 Re: how to optimize my c-extension functions