MS Access 完全外连接中出现莫名其妙的行为?
我尝试在 MS Access 中对两个表 CMVSC
和 TOXOSC
进行完全外部联接,以检查两个表/其中一个表中包含哪些 ID:
(SELECT * FROM CMVSC LEFT JOIN TOXOSC ON CMVSC.ID = TOXOSC.ID)
UNION
(SELECT * FROM TOXOSC LEFT JOIN CMVSC ON TOXOSC.ID = CMVSC.ID);
查询可以执行,但没有达到我的预期。
CMVSC 中的前几条记录(按 ID 升序排序)为:
ID CMV_NEGDATE CMV_POSDATE
10245 04.02.2010 28.06.1999
10642 08.10.1998 05.09.1991
TOXOSC 中的前几条记录(按 ID 升序排序)为:
ID TOXO_NEGDATE TOXO_POSDATE
10120 22.11.1993 05.04.1991
10261 09.02.1998 23.02.1996
以下是上述查询中的前两条记录:
CMVSC.ID CMV_NEGDATE CMV_POSDATE TOXOSC.ID TOXO_NEGDATE TOXO_POSDATE
10120 22.11.1993 05.04.1991
10245 04.02.2010 28.06.1999
请注意 TOXOSC< 中的记录如何/code> 被分配给
CMV*
变量,就像来自 CMVSC
的记录一样。
这怎么可能?
I attempt to do a full outer join of two tables CMVSC
and TOXOSC
in MS Access in order to examine which IDs are contained in both/just one of the tables:
(SELECT * FROM CMVSC LEFT JOIN TOXOSC ON CMVSC.ID = TOXOSC.ID)
UNION
(SELECT * FROM TOXOSC LEFT JOIN CMVSC ON TOXOSC.ID = CMVSC.ID);
The query can be executed, but does not yield what I expected.
The first few records (sorted by ascending ID) in CMVSC are:
ID CMV_NEGDATE CMV_POSDATE
10245 04.02.2010 28.06.1999
10642 08.10.1998 05.09.1991
The first few records (sorted by ascending ID) in TOXOSC are:
ID TOXO_NEGDATE TOXO_POSDATE
10120 22.11.1993 05.04.1991
10261 09.02.1998 23.02.1996
And here are the first two records from the above query:
CMVSC.ID CMV_NEGDATE CMV_POSDATE TOXOSC.ID TOXO_NEGDATE TOXO_POSDATE
10120 22.11.1993 05.04.1991
10245 04.02.2010 28.06.1999
Note how the record from TOXOSC
got assigned to the CMV*
variables, just as the record from CMVSC
.
How is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因是第一个子查询首先有
CMVSC
表,然后是TOXOSC
表。第二个子查询的顺序相反。UNION
获取列,并使用第一个子查询的标题(因此混合)作为列标题。试试这个:另一种方法是同时使用
LEFT
和RIGHT
连接:The reason is that first subquery has first the
CMVSC
table and then theTOXOSC
one. The second subquery has them in opposite order. TheUNION
takes the columns as they come and uses as columns titles the titles from the first subquery (therefore the mixing). Try this:Another way would be to use both
LEFT
andRIGHT
join: