我使用的是microsoft sql server,我的查询格式如下(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)
我怎么能做得很好?我正在考虑使用类似的方法找到一组CORRECT键(不能使用除了 - 运行sql server 2000)
Select A,B
from table1
not exists ( select A,B from bad table)
然后使用主查询进行内连接。你觉得怎么样?
答案 0 :(得分: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)
将是一个好方法
答案 1 :(得分: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