什么是 MS Access SQL 相当于 a.key IS NULL 和 b.key IS NULL 的 FULL OUTER JOIN
What is the MS Access SQL equivalent of FULL OUTER JOIN with a.key IS NULL and b.key IS NULL
我想在 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 等同于我正在尝试执行的 示例查询?
使用:
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);
我想在 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 等同于我正在尝试执行的 示例查询?
使用:
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);