我正在尝试在Darby Query中进行内部联接。它工作正常,但是从两个表的数据库中获取数据时却缺少一些结果。当我尝试更多数据时,它会给出一些正确的结果,但并非所有结果都是正确的。
表X和Y数据。
表X:
A B Time
5509 7015 11:19:40
9506 7072 11:19:43
表Y:
A B Time
7072 9506 11:19:43
6247 669 11:19:45
查询:
SELECT orig.A, orig.B, orig.TIME
from X orig INNER JOIN
(SELECT A, B, TIME
from X
) t1
ON t1.B = orig.A and t1.TIME = orig.TIME UNION ALL
SELECT orig.A, orig.B, orig.TIME
from Y orig INNER JOIN
(SELECT A, B, TIME
from Y
) t1
ON t1.B = orig.A and t1.TIME = orig.TIME
ORDER BY TIME
查询不返回结果。
必填结果:
A B Time
9506 7072 11:19:43
7072 9506 11:19:43
答案 0 :(得分:0)
您似乎想要:
select x.A, x.B, x.TIME
from x
where exists (select 1 from y where y.time = x.time)
union all
select y.A, y.B, y.TIME
from y
where exists (select 1 from x where x.time = y.time);
如果不返回任何行,则时间可能略有不同。您可以将=
替换为以下表达式:
y.time > x.time - interval 1 second and
y.time < x.time + interval 1 second