Skip to main content
added 221 characters in body
Source Link

You can create a view like:

create view all_config as
select y.id, x.accountId, y.config
from accounts x
cross join defaultconfig y
where not exists (
    select 1 from accountconfig z
    where x.accountid = z.accountid
      and y.id = z.defaultconfigid
)
union all
select a.id, a.accountid, a.defaultconfig
from accountconfig a

and select from there to get the current config for an account. Note that you should only store information that is changed in AccountConfig. Don't use null as a merker. In your example, id 1 in AccountConfig should be removed. The view will provide this info from the default table.

You can create a view like:

create view all_config as
select y.id, x.accountId, y.config
from accounts x
cross join defaultconfig y
where not exists (
    select 1 from accountconfig z
    where x.accountid = z.accountid
      and y.id = z.defaultconfigid
)
union all
select a.id, a.accountid, a.defaultconfig
from accountconfig a

and select from there to get the current config for an account

You can create a view like:

create view all_config as
select y.id, x.accountId, y.config
from accounts x
cross join defaultconfig y
where not exists (
    select 1 from accountconfig z
    where x.accountid = z.accountid
      and y.id = z.defaultconfigid
)
union all
select a.id, a.accountid, a.defaultconfig
from accountconfig a

and select from there to get the current config for an account. Note that you should only store information that is changed in AccountConfig. Don't use null as a merker. In your example, id 1 in AccountConfig should be removed. The view will provide this info from the default table.

Source Link

You can create a view like:

create view all_config as
select y.id, x.accountId, y.config
from accounts x
cross join defaultconfig y
where not exists (
    select 1 from accountconfig z
    where x.accountid = z.accountid
      and y.id = z.defaultconfigid
)
union all
select a.id, a.accountid, a.defaultconfig
from accountconfig a

and select from there to get the current config for an account