表格1
Id value
1 1
1 4
表2
id Detailid value
1 1 1
1 2 2
1 3 3
1 4 4
1 5 5
1 6 6
我要结果
Id Detaild value
1 1 1
1 2 null
1 3 null
1 4 4
1 5 null
1 6 null
我下面的查询给了我 2 额外的空行
select distinct t1.id,t2.detailid
,case when t1.value IN(t2.Value) then t1.value else null end as value
from table1 t1
left outer join table2 t2
on t1.id= t2.id
我正进入(状态
Id Detaild value
1 1 null ----dont need
1 1 1
1 2 null
1 3 null
1 4 null ---dont need
1 4 4
1 5 null
1 6 null