gpt4 book ai didi

sql - Derby 数据库 : sql update the results of a select statement

转载 作者:行者123 更新时间:2023-12-02 09:45:48 24 4
gpt4 key购买 nike

我有两个表:

元素:

ID (int. key)
TYPE (String)

ELEMENT_ATTRIBUTES:

ELEMENT_ID (int)
ATTR_NAME (String)

(我忽略了原始表中的字段,这些字段对于这个问题不是必需的)

我想做这样的事情:

UPDATE ELEMENT e, ELEMENT_ATTRIBUTES a
SET a.ATTR_NAME='new name'
WHERE e.ID = a.ELEMENT_ID
AND e.TYPE = 'a specific type'
AND a.ATTR_NAME = 'old name'

这在 derby sql 中可能吗?

最佳答案

查看the Derby Reference Manual on the UPDATE statement语法是:

{
UPDATE table-Name [[AS] correlation-Name]
SET column-Name = Value
[ , column-Name = Value} ]*
[WHERE clause] |
UPDATE table-Name
SET column-Name = Value
[ , column-Name = Value ]*
WHERE CURRENT OF
}

所以不,你不能像你的问题那样执行查询。您需要将其修改为:

UPDATE ELEMENT_ATTRIBUTES a
SET a.ATTR_NAME='new name'
WHERE a.ATTR_NAME = 'old name'
AND EXISTS (SELECT 1
FROM ELEMENT e
WHERE a.ELEMENT_ID = e.ID AND e.TYPE = 'a specific type')

关于sql - Derby 数据库 : sql update the results of a select statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13762513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com