pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A_Schnabel@t-online.de
To: trebischt <trebischt@freemail.hu>
To: pgsql-sql@postgresql.org
Subject: Re: To query many tables.
Date: Sat, 15 Sep 2001 09:47:28 +0200
Message-ID: <006501c13dba$ab8954c0$0201a8c0@aschnabel.homeip.net> (raw)
References: <f391b602.0109111047.4735563b@posting.google.com>

----- Original Message -----
From: "trebischt" <trebischt@freemail.hu>
Subject: [SQL] To query many tables.


> Hi,
>
> The query looks like this:
>
> select * from table1 f, table2 s, table3 t, table4 fo, table5 fi,
> table6 si, table 7 se, table8 e, table9 n, table10 ten, table 11 el,
> table 12 tw ...
> where f.id=s.id
> and f.id=t.id
> and f.id=fo.id
> and f.id=fi.id
> and so on...
>
> Is this the right way, or are there any better solution?
> How do the professionals make that big queries?

Yes, this is ONE right way. Professionals do it the same way ;-).
But you can use the "JOIN"-Clause instead. It's your desicion, what's more
readable.
With JOIN it would look like this:

select * FROM
    table1 f    JOIN    table2 s ON f.id = s.id
            JOIN    table 3 t ON f.id = t.id
    .... more joins here ....
WHERE xxx

If you use your way or this simple joins, there must be a row with the same
id in each table, to have it shown by your query. If you want to see all
records, that have an entry in at least one table you have to use outer
joins. More details on SELECT statemants and joins are here:
http://www.postgresql.org/idocs/index.php?queries.html.

Andre




view thread (2+ messages)

Message-ID: <006501c13dba$ab8954c0$0201a8c0@aschnabel.homeip.net>
Permalink:  ../006501c13dba$ab8954c0$0201a8c0@aschnabel.homeip.net/
Also on:    postgresql.org/message-id/006501c13dba$ab8954c0$0201a8c0@aschnabel.homeip.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: A_Schnabel@t-online.de, trebischt@freemail.hu
  Subject: Re: To query many tables.
  In-Reply-To: <006501c13dba$ab8954c0$0201a8c0@aschnabel.homeip.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox