SQL查询-筛选主键

SQL查询-筛选主键,sql,sql-server-2000,Sql,Sql Server 2000,我使用的是microsoft sql server,查询的格式如下(表1主键为(A,B)): 我怎样才能做得好呢?我正在考虑使用类似(不能使用,除非-运行sql server 2000)的方法查找正确的密钥集 然后将其与主查询进行内部连接。你觉得怎么样 Select table1.A, table1.B, table2.C, Table3.D from table1 T1 left outer join table2 on table1.A = table2.A left outer join

我使用的是microsoft sql server,查询的格式如下(表1主键为(A,B)):

我怎样才能做得好呢?我正在考虑使用类似(不能使用,除非-运行sql server 2000)的方法查找正确的密钥集

然后将其与主查询进行内部连接。你觉得怎么样

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)
这是个好办法

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
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)
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