Insert into with originTable.id = destinationTable.id [英] Insert Into with where originTable.id = destinationTable.id
本文介绍了Insert into with originTable.id = destinationTable.id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题,但我似乎无法找到我需要的东西,例如只给我id = 1等等。
我的伪代码我想要实现但不起作用(错误)
INSERT INTO tableB b
SELECT a.l_desc,a.s_desc FROM tableA a where on a.id = b.id
id在两个表中都是相同的,所以插入正确的描述
解决方案
你的tableB
已经有了b.id值,所以你不能使用insert
Query .your only option更新
它
更新 b set b.l_desc = a.l_desc,b.s_desc = a.s_desc
来自 tableB as b inner 加入 tableA 其中 a.id = b.id
你应该使用更新查询而不是插入因为你已经在表格中有记录B
update b set l_desc = a.l_desc,s_desc = a.s_desc
来自 tableB, tableA a 其中 a.id = b.id
试试这个:
UPDATE tableB set l_desc = a.l_desc,s_desc = a.s_desc
FROM tableA a WHERE a.id = tableB.id
Simple question but i can't seem to find what i need, as examples are giving me only where id=1 etc.
pseudo code of what i'm wanting to achieve but doesn't work (errors)
INSERT INTO tableB b
SELECT a.l_desc, a.s_desc FROM tableA a where on a.id = b.id
id's are same in both tables so insert the correct descriptions
解决方案
yourtableB
have b.id values already so you can't useinsert
Query .your only optionUpdate
it
update b set b.l_desc=a.l_desc,b.s_desc=a.s_desc from tableB as b inner join tableA a where a.id = b.id
you should use update query instead of insert as you already have record in your tableB
update b set l_desc=a.l_desc,s_desc=a.s_desc from tableB , tableA a where a.id = b.id
Try this:
UPDATE tableB set l_desc=a.l_desc,s_desc=a.s_desc FROM tableA a WHERE a.id=tableB.id
这篇关于Insert into with originTable.id = destinationTable.id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文