sql - select case when select query -
i need in solving query. want fetch choicename based on conditions.
below code snippet
select psc.sku_id, psc.choice_id, psc.option_id, po.*, ( case when po.std_id = 0 (select * prodopt_choices option_id = psc.option_id , choice_id = psc.choice_id) when po.std_id = 1 (select * stdopt_choices option_id = psc.option_id , choice_id = psc.choice_id) ) choicename prod_sku_combos psc left join product_options po on po.option_id = psc.option_id psc.sku_id = #sku_id#
any appreciated.. tia
if need 1 column (e.g. choicename
), , joins 1:(0-1) can use left join
each, , case
expression:
select psc.sku_id, psc.choice_id, psc.option_id, po.* , choicename = case when po.std_id = 0 poc.choicename when po.std_id = 1 soc.choicename else soc.choicename end prod_sku_combos psc left join product_options po on po.option_id = psc.option_id left join prodopt_choices poc on poc.option_id = psc.option_id , poc.choice_id = psc.choice_id left join stdopt_choices soc on soc.option_id = psc.option_id , soc.choice_id = psc.choice_id psc.sku_id = #sku_id#
Comments
Post a Comment