pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTo query many tables.
2+ messages / 2 participants
[nested] [flat]
* To query many tables.
@ 2001-09-11 18:47 trebischt <trebischt@freemail.hu>
2001-09-15 07:47 ` Re: To query many tables. Andre Schnabel <A_Schnabel@t-online.de>
0 siblings, 1 reply; 2+ messages in thread
From: trebischt@freemail.hu @ 2001-09-11 18:47 UTC (permalink / raw)
To: pgsql-sql
Hi,
I have to query many tables (about 18 tables)
from a database to field a riport in HTML.
I can make the query and it works (I think), but it's a bit strange to
me.
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?
Thanks in advance!
Regards,
Trebb
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: To query many tables.
2001-09-11 18:47 To query many tables. trebischt <trebischt@freemail.hu>
@ 2001-09-15 07:47 ` Andre Schnabel <A_Schnabel@t-online.de>
0 siblings, 0 replies; 2+ messages in thread
From: A_Schnabel@t-online.de @ 2001-09-15 07:47 UTC (permalink / raw)
To: trebischt <trebischt@freemail.hu>; pgsql-sql
----- 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-09-15 07:47 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-11 18:47 To query many tables. trebischt <trebischt@freemail.hu>
2001-09-15 07:47 ` Andre Schnabel <A_Schnabel@t-online.de>
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