使用下面的查询将记录从一个表复制到另一个表,但得到错误
insert into table1 (datestamp)
select datestamp
from table2
where table1.datestamp is null我想将datestamp的记录从表2复制到表1,其中表1中的datestamp为空。
发布于 2013-04-16 23:46:44
这就是你的意思吗?
insert into table1 (datestamp)
select datestamp
from table2
where table2.datestamp is null您正在where子句中引用table1日期戳,这是不允许的。
也许你真的想要一个update。如果是这样,您需要一种链接这两个表的方法:
update t1
set datestamp = t2.datestamp
from table1 t1 join
table2 t2
on t1.id = t2.id
where t1.datestamp is null发布于 2013-04-16 23:53:45
我假设这些表是通过某个唯一的id联系在一起的?我们称其为tableID。
UPDATE table1 t1, table2 t2
SET t1.datestamp = t2.datestamp
WHERE t1.datestamp IS NULL
AND t1.tableID = t2.tableIDhttps://stackoverflow.com/questions/16041361
复制相似问题