pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Rewrite multiple joins...
2+ messages / 2 participants
[nested] [flat]

* Rewrite multiple joins...
@ 2009-08-21 03:17  tripplowe <tripplowe@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: tripplowe @ 2009-08-21 03:17 UTC (permalink / raw)
  To: pgsql-sql


Hey Folks,

I have a query that seems like it will never end.  I'm hoping you can help
me rewrite it.

I have 4 tables that contain information about house sales within the state
(sale, taxes, property, buyer).  Each table has an 'id' field that links
each record.  I am just trying to flatten these files so I will have all of
the information in a single file.  Below is my attempt to do so.  Is there a
more efficient way to rewrite the joins?

select * from sale, taxes, property, buyer 
where sale.id = taxes.id and sale.id = property.id and sale.id = buyer.id

I'm using postgresql 8.3 on a Windows 7 machine.  

Thank You,
-Tripp
-- 
View this message in context: http://www.nabble.com/Rewrite-multiple-joins...-tp25073534p25073534.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Rewrite multiple joins...
@ 2009-08-21 15:15  Rob Sargent <robjsargent@gmail.com>
  parent: tripplowe <tripplowe@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Rob Sargent @ 2009-08-21 15:15 UTC (permalink / raw)
  To: tripplowe <tripplowe@gmail.com>; +Cc: pgsql-sql

Well indexing (or lack thereof) could be the real problem but you could 
try "chaining" the tables

select * from sale s, taxes t, property p, buyer b
where s.id = t.id and t.id = p.id and p.id = b.id

and see if that (or other combination) changes the query plan appreciably.


(I would have to wonder if all those records are really unique per 
sale.id? e.g. multiple buyers per unit sold or school and property tax 
in separate records. And wondering further why, if you have sql access, 
do you need a single table. Maybe you want a view for convenience (e.g. 
select * from view_of_sales where lower(county) like 'a%' )?

tripplowe wrote:
> Hey Folks,
>
> I have a query that seems like it will never end.  I'm hoping you can help
> me rewrite it.
>
> I have 4 tables that contain information about house sales within the state
> (sale, taxes, property, buyer).  Each table has an 'id' field that links
> each record.  I am just trying to flatten these files so I will have all of
> the information in a single file.  Below is my attempt to do so.  Is there a
> more efficient way to rewrite the joins?
>
> select * from sale, taxes, property, buyer 
> where sale.id = taxes.id and sale.id = property.id and sale.id = buyer.id
>
> I'm using postgresql 8.3 on a Windows 7 machine.  
>
> Thank You,
> -Tripp
>   



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2009-08-21 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-08-21 03:17 Rewrite multiple joins... tripplowe <tripplowe@gmail.com>
2009-08-21 15:15 ` Rob Sargent <robjsargent@gmail.com>

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