MS Access查询不存在

时间:2016-04-27 15:39:54

标签: sql ms-access

我一直在环顾四周,并且无法完成这项工作。

我有两个表来自两个查询

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,但是因为我一直都遇到语法错误而无法正常工作。

感谢您的时间, 西蒙。

2 个答案:

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

看看:This excellent answer

它回答了如何使用NOT EXISTS的问题。 顺便说一下,我观察到IS NULL子句更快。