2

私はMicrosoftSQLServerを使用しており、クエリは次の形式です(table1の主キーは(A、B)です)。

Select table1.A, table1.B, table2.C, Table3.D
from table1
left outer join table2 on table1.A = table2.A
left outer join tabl3 on table1.B = table3.B

//Here comes the question
//Except (A,B) in ( select A,B from BadTable)

どうすればうまくできますか?私はsthlikeを使用して正しいキーのセットを見つけることを考えていました(SQL Server 2000を実行している以外は使用できません)

Select A,B
from table1
not exists ( select A,B from bad table)

次に、それをメインクエリと内部結合します。どう思いますか?

4

2 に答える 2

1
Select table1.A, table1.B, table2.C, Table3.D
from table1 T1
left outer join table2 on table1.A = table2.A
left outer join tabl3 on table1.B = table3.B
where not exists (select 1 from badTable where A = T1.A and B = T1.B)

良い方法だろう

于 2012-09-21T15:02:16.283 に答える
0
Select table1.A, table1.B, table2.C, Table3.D ,badtable.*
from table1 
left join table2 on table1.A = table2.A 
left join table3 on table1.B = table3.B 
left join badtable on table1.a = badtable.a
    and table1.b = badtable.b
where badtable.a is null
于 2012-09-21T15:06:29.023 に答える