1

我想在 MS Access SQL 中执行的示例查询

SELECT *
FROM TableA AS a
FULL OUTER JOIN TableB AS b
ON a.key = b.key
WHERE a.key IS NULL
OR b.key IS NULL

由于 MS Access SQL 不允许 FULL OUTER JOIN,我尝试使用下面的代码,但结果不正确。

SELECT *
FROM (TableA AS a
LEFT JOIN TableB AS b
ON a.key = b.key)
RIGHT JOIN TableB AS c
ON a.key = c.key
WHERE b.key IS NULL
OR a.key IS NULL

有谁知道如何构建我试图执行的上面示例查询的 MS Access SQL 等效项?

4

1 回答 1

0

利用:

select . . . 
from a
where not exists (select 1 from b where b.key = a.key)
union all
select . . .
from b
where not exists (select 1 from a where a.key = b.key);

. . .是您想要的列。

如果你使用过,你可以使用*

select a.*, b.*
from a left join
     b
     on 1 = 0
where not exists (select 1 from b where b.key = a.key)
union all
select a.*, b.*
from b left join
     a
     on 1 = 0
where not exists (select 1 from a where a.key = b.key);
于 2020-04-04T02:01:23.187 回答