【发布时间】:2020-07-24 22:09:58
【问题描述】:
我有 2 个表我想比较数据并将差异插入到第三个表中,例如我有
table A
number Status
1111 C
2222 O
3333 O
4444 C
Table B
number status
1111 c
2222 O
5555 C
6666 O
现在我想插入表 B 中缺少的表 A 中的数据,即 3333 和 4444
我有这个问题
Insert into Table C (number,Status)
Select a.number,a.Status from Table A a
left join Table B b ON b.number = a.number
where B.number is Null
但它正在向表 C 中插入 Null 数据
【问题讨论】:
-
这个查询应该有效。 将 null 插入 tableC 是什么意思?
-
你用的是mysql还是sql-server?请只保留相关的数据库标签。
-
@GMB 我正在使用 sql server,下次我会注意的。谢谢。
标签: mysql sql sql-server database ssms-2016