基于多个sql表中的查找更新单个条目
我试图更新一个表中的条目,以反映我在另一个表中存储的内容,这是基于另一个表中某个项的类别。哦,我的项目是由字母键和数字键组成的 到目前为止我有基于多个sql表中的查找更新单个条目,sql,postgresql,Sql,Postgresql,我试图更新一个表中的条目,以反映我在另一个表中存储的内容,这是基于另一个表中某个项的类别。哦,我的项目是由字母键和数字键组成的 到目前为止我有 update itmHistory set ithLocation = storLocation from items, storage where ithAKey in (select storAKey from storage) and ithNKey in (select storNKey from storage) and storCat
update itmHistory
set ithLocation = storLocation from items, storage
where ithAKey in (select storAKey from storage)
and ithNKey in (select storNKey from storage)
and storCategoryName = itmCategoryName;
最终发生的情况是,items表中itmLocation的每个实例都被设置为最后一个条目,其中storCategoryName=itmCategoryName
有什么想法可以在每次发现时进行更新吗
编辑:表格信息:
itmHistory: ithAKey varchar(3) PK
ithNKey int PK
ithStart timestamp PK
ithEnd timestamp
ithLocation text
items: itmAKey varchar(3) PK
itmNKey int PK
itmCategoryName text
storage: storName text PK
storCategoryName text
storLocation text
PK=主键根据您的表信息,这个怎么样
UPDATE ih
SET ih.ithLocation = s.storLocation
FROM itmHistory ih
JOIN items i ON ih.ithAKey = i.itmAkey AND ih.ithNKey=i.itmNKey
JOIN Storage s ON i.itemCategoryName = s.storCategoryName
为什么MySQL会出现在标签列表中?它在这里相关吗?请提供表定义。我不完全确定连接实际上是如何工作的,你能解释一下吗?这样我就可以知道它将来可以解决什么样的问题了?