【发布时间】:2013-02-14 10:03:20
【问题描述】:
如何比较两个表并根据结果做出反应。例如。 我有 2 个表(精确结构):tableA(key, text) 和 tableB(key, text) 和一个结果表(key, field, case)。
if key is in tableA, but not in tableB --> case: insert
if key is in tableB, but not in tableA --> case: delete
if key is in tableA and in tableB, but the text is different -> update
if key is in tableA and in tableB, and the text is the same -> nothing
结果表如下:
key | text | case
------------------
1 | t1 | update
2 | t2 | delete
3 | t3 | insert
4 | t4 | nothing
是否可以只用一个查询来完成?
获取插入(删除反之亦然):
SELECT key FROM tableA
MINUS
SELECT key FROM tableB;
【问题讨论】: