case
を使用する場合 、1つだけのレコードを返す必要があります-1以下。目的の結果を得るには、左外部結合を使用します(table1をtable2に結合する方法があると仮定します)が、table1.c1のチェックをに追加します。 c1 <> '1'
select
coalesce(table2.c1, table1.c1) c1,
coalesce(table2.c2, table1.c2) c2,
coalesce(table2.c3, table1.c3) c3
from table1
left outer join table2
on (your keys here)
and table1.c1 <> '1' -- This gets table1 if c1 = '1';
このソリューションは、table1とtable2が関連していることを前提としています。それらを関連付けることができない場合は、c1 ='1'であるtable1からすべての値を取得し、それらをすべてのtable2行に結合するunionallを使用できるように思えます。必要に応じて、c1<>'1'の場合にのみtable2値を含めることができます。
select c1, c2, c3 from table1 where c1 = '1'
union all
select c1, c2, c3 from table2; -- where c1 <> '1' -- if necessary
更新
サンプルデータと期待される出力に基づいて、上記の2番目のクエリを使用してください:
select c1, c2, c3 from table1 where c1 = '1'
union all
select c1, c2, c3 from table2 where c1 <> '1'
SQLフィドル: http://www.sqlfiddle.com/#!4/ 710f0 / 1/0