"union" vs. left join

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: "union" vs. left join
Date: 2009-03-03 20:26:22
Message-ID: 49AD926E.3020406@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Good morning,

Would it be possible to know that whether "union" is quicker than "left
join" in a general sense?

Queries:
========================
(1) union
select a.*, b.value
from a
left join b
union
select a.*, c.value
from a
left join c

(2) left join
select distinct a.*,
case when ... then
b.value
else
c.value
from a
left join b
left join c

Will (1) be more efficient than (2) or vice versa? Or it really depends
on data

Thanks a lot!
Lu Ying

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message ries van Twisk 2009-03-03 20:33:43 Re: "union" vs. left join
Previous Message Andreas Kretschmer 2009-02-27 21:52:16 Re: counts of groupings by date year-month