2

我正在使用 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)

我怎么能做得很好?我正在考虑使用类似的东西找到一组正确的键(不能使用,除了 - 运行 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 回答