【发布时间】:2023-03-29 17:20:01
【问题描述】:
我正在使用 mysql。我有两张桌子。它们不共享密钥(但有一些共同的属性)。我必须从 tableA 中选择 tableB 中不存在的行。基于谷歌搜索和堆栈溢出,我编写了这个查询
select ta.a, ta.b, ta.c from
(select a, b, c, -1 * c d from TableA) ta
left join TableB tb on (ta.a = tb.a and ta.b = tb.b and ta.d = tb.c)
where tb.a is null and tb.b is null and tb.c is null;
但我不确定这是否正确。你能确认或告诉我我写的是否正确吗?
最后我不应该从 TableA 中获取任何行,如果 TableB 有一行具有相同的 a 和 b 值且 c 为负值。
【问题讨论】: