better approach: case or join

From: chester c young <chestercyoung(at)yahoo(dot)com>
To: sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: better approach: case or join
Date: 2007-03-19 01:21:54
Message-ID: 828472.77350.qm@web54308.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

from id extracting name from several tables. which is generally the
better approach?

select case when tab_tla='usr' then (select name from users where ... )
case when tab_tla='con' then (select title from contents where
...)
end as name;

as versus

select name
from users
where tab_tla='usr' and ...
join
select title
from contents
where tab_tla='con' and ...

I assume the former since the optimizer does not examine whether the
entire where clause might be false before executing the query.

thanks,
chester


____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html

Browse pgsql-sql by date

  From Date Subject
Next Message roopa perumalraja 2007-03-19 02:56:01 Help with sub query
Previous Message T E Schmitz 2007-03-18 19:51:28 triple self-join crawling