I have a classic self-joinable table: (id, profile, parent_id) where parent_id points to id.
To produce a table of inherited values I have:
select t1.id, case when t2.profile is null t1.profile else t2.profile end
from mytable t1 LEFT JOIN mytable t2
on t2.parent_id = t1.id
Problem is that my table contains 20 profile fields so I would have to have the case statement repeated 20 times.
Can I instead use:
select t1.id, t2.profile
from mytable t1 LEFT JOIN mytable t2
on isnull(t2.parent_id,t1.id) = t1.id
To produce a table of inherited values I have:
select t1.id, case when t2.profile is null t1.profile else t2.profile end
from mytable t1 LEFT JOIN mytable t2
on t2.parent_id = t1.id
Problem is that my table contains 20 profile fields so I would have to have the case statement repeated 20 times.
Can I instead use:
select t1.id, t2.profile
from mytable t1 LEFT JOIN mytable t2
on isnull(t2.parent_id,t1.id) = t1.id