是否可以在更新语句中使用同一个表两次?
我正在尝试按照以下方式编写查询:
UPDATE Table i2
SET value = 0
WHERE EXISTS (SELECT 1 FROM Table i1 WHERE i2.ID = i1.ID+1)
问题是我收到“'i2'附近的语法不正确”。我猜这是因为它不喜欢给正在更新的表起一个昵称,但如果是这样的话,我应该如何引用它呢?
I'm trying to write a query along these lines:
UPDATE Table i2
SET value = 0
WHERE EXISTS (SELECT 1 FROM Table i1 WHERE i2.ID = i1.ID+1)
The problem is that I'm getting "Incorrect syntax near 'i2'." I'm guessing this is because it doesn't like giving a nickname to a table being updated, but if that's the case, how am I supposed to reference it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新不仅必须直接在表上进行,还可以使用
From
子句中引用的表的别名。An update does not only have to be on a table directly you can use an alias from a table referenced in the
From
clause.“SET”子句中的“值”是SQL的关键字。此外,您的逻辑似乎是清除除第一行之外的所有“值”,这是您的目标吗?
The "value" within the "SET" clause is a keyword of SQL.Further, your logic seems to be clearing all the "value"s except the first row, is it your goal?