Truusvlugindewind
Programmer
Suppose the functional requitement:
Read a, b, c from tab01.
When b = 2 read k from tab02 as well (using c as foreign key). The tab02 row does not have to exist.
You can code
in the host language you code
if b in tab01 = 2 and k in tab02 not = space then display "yes"
But when I look at this I think to myself: "when B is not 2 then I do not have to do a table-looup for tab02. Would it not be better to include this condition in the "ON" clause of my join? So:
What would you do:
include the condition in the "ON" clause: probabley more efficient but not so nice readable, or just leave it out and who cares about the superfluous table-lookups?
Read a, b, c from tab01.
When b = 2 read k from tab02 as well (using c as foreign key). The tab02 row does not have to exist.
You can code
Code:
select t1.a
, t1.b
, t1.c
,coalesce(t2.k,space)
from tab01 t1
left outer
join tab02 t2
on t2.c = t1.c
where t1.a = :a
if b in tab01 = 2 and k in tab02 not = space then display "yes"
But when I look at this I think to myself: "when B is not 2 then I do not have to do a table-looup for tab02. Would it not be better to include this condition in the "ON" clause of my join? So:
Code:
select t1.a
, t1.b
, t1.c
,coalesce(t2.k,space)
from tab01 t1
left outer
join tab02 t2
on [COLOR=red]t1.b = 2 and[/color]
t2.c = t1.c
where t1.a = :a
include the condition in the "ON" clause: probabley more efficient but not so nice readable, or just leave it out and who cares about the superfluous table-lookups?