レシピ (より一般的なカテゴリ) に関連付けることができる構成データのテーブルがあります。
このような:
レシピ:
ID Name
1 Default
2 A
3 B
設定データ
ID equipment ParentID RecipeID
1 3420 1 1
2 3420 1 2
3 3421 1 1
4 3421 1 2
5 3422 1 1
レシピ「A」のすべての構成データを選択し、レシピ A が構成データ行に構成されていない場合に「デフォルト」値にフォールバックする方法を知りたいです。次に、これを取得します:
ID equipment ParentID RecipeID
2 3420 1 2
4 3421 1 2
5 3422 1 1
私はすでにこのようなものを見つけましたが、それが良いアプローチであるかどうかはわかりません:
select * from ConfigurationData
where RecipeID=2 and parentID=1
union
select * from ConfigurationData
where RecipeID=1 and parentID=1
and Equipment not in (select Equipment from ConfigurationData
where RecipeID=2 and parentID=1)