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 17:43:27
Message-ID: 224EF699-632F-11D9-8618-0050E410655F@fjrhome.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

As for the first part, try this:

(SELECT file_name FROM file_info_1 WHERE file_name = '/') UNION
(SELECT file_name FROM file_info_2 WHERE file_parent_dir = '/') UNION
(SELECT file_name FROM file_info_3 WHERE file_parent_dir = '/')

As for sorting the combined results, it would be along the lines of the
following, although I suspect I am missing something here (untested, if
it doesn't work, someone else might know how to fix it for you):

SELECT file_name
FROM ((SELECT file_name FROM file_info_1 WHERE file_name = '/') UNION
(SELECT file_name FROM file_info_2 WHERE file_parent_dir
= '/') UNION
(SELECT file_name FROM file_info_3 WHERE file_parent_dir
= '/')) AS a
ORDER BY file_name

On Jan 10, 2005, at 12:22 PM, Madison Kelly wrote:

> Hi all,
>
> I have another question, I hope it isn't too basic. ^.^
>
> I want to do a select from multiple tables but not join them. What I
> am trying to do is something like this (though this doesn't work as I
> need):
>
> SELECT a.file_name, b.file_name, c.file_name FROM file_info_1 a,
> file_info_2 b, file_info_3 c WHERE a.file_name='/' AND
> b.file_parent_dir='/' AND c.file_parent_dir='/';
>
> That returns every combination of the results from the three tables
> which is a huge number. What I need is to return all of the matches in
> all of the tables in a single column. Once I have all the matches in
> one column the next trick is to sort the combined results (any tips
> there?).
>
> I hope the question was clear. Please let me know if it wasn't.
> Thanks!
>
> Madison
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>
- -----------------------------------------------------------
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)

iD8DBQFB4r6/7aqtWrR9cZoRAgxhAJ9p1tJBs+xmlZ/TlgKVOaAC+FtCEACfa+1g
Uf8dStwt9O2hwlP56chWabk=
=a+F/
-----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

Browse pgsql-general by date

  From Date Subject
Next Message Alex Turner 2005-01-10 17:44:54 Re: SELECT from multiple tables (not join though)
Previous Message Janning Vygen 2005-01-10 17:42:57 Re: SELECT from multiple tables (not join though)