Re: Subqueries or Joins? Problems with multiple table query - Mailing list pgsql-general

From Thom Brown
Subject Re: Subqueries or Joins? Problems with multiple table query
Date
Msg-id bddc86151002230528v5e9da7b9jc0f49de715307c07@mail.gmail.com
Whole thread Raw
In response to Re: Subqueries or Joins? Problems with multiple table query  (Stefan Schwarzer <stefan.schwarzer@grid.unep.ch>)
Responses Re: Subqueries or Joins? Problems with multiple table query
List pgsql-general
On 23 February 2010 13:23, Stefan Schwarzer
<stefan.schwarzer@grid.unep.ch> wrote:
>> Select countries.name, basel.year, basel.value, cites.year, cites.value
>> From countries
>> Left Join basel on basel.id_country = countries.id_country and
>> basel.value=1
>> Left Join cites on cites.id_country = countries.id_country and
>> cites.value=1
>
> I would have thought so, but the query turns forever.

How many rows in each of your tables, and what indexes do you have?

You may also wish to review Andreas' suggestions as they propose a
more sensible table structure rather than having a table for each
convention.

You may also be interested in the tablefunc contrib module to help
present your data in the format you require rather than having a join
for each convention:
http://www.postgresql.org/docs/8.4/static/tablefunc.html

Thom

pgsql-general by date:

Previous
From: Stefan Schwarzer
Date:
Subject: Re: Subqueries or Joins? Problems with multiple table query
Next
From: Richard Huxton
Date:
Subject: Re: Alternative to UPDATE (As COPY to INSERT)