我一直在环顾四周,并且无法完成这项工作。
我有两个表来自两个查询
SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount as Val1 FROM [Account Combination];
和
SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount AS Val1 FROM [Account Information] INNER JOIN ([Cost Center] INNER JOIN [Account Combination] ON [Cost Center].[Cost Center Number] = [Account Combination].[Cost Center]) ON [Account Information].[Account Number] = [Account Combination].[Account Number];
Table1有1800行,Table2有1600.我想读一下Table1中找到的,而不是Table2中的200,
我已经尝试了Table1 NOT EXISTS Tabel2,但是因为我一直都遇到语法错误而无法正常工作。
感谢您的时间, 西蒙。
答案 0 :(得分:4)
您可以使用LEFT OUTER JOIN
以及WHERE
条件(如下所示)来完成此操作
select t1.*
from (SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount as Val1
FROM [Account Combination]) t1
left join (
SELECT [Account Combination].[Account Number] & [Account Combination].[Cost Center] & [Account Combination].Amount AS Val1
FROM [Account Information] INNER JOIN ([Cost Center] INNER JOIN [Account Combination]
ON [Cost Center].[Cost Center Number] = [Account Combination].[Cost Center])
ON [Account Information].[Account Number] = [Account Combination].[Account Number]) t2
on t1.Val1 = t2.Val1
where t2.Val1 is null;
答案 1 :(得分:0)
它回答了如何使用NOT EXISTS的问题。 顺便说一下,我观察到IS NULL子句更快。