我试图只更新表中的某些行,但其他行得到 NULL
我正在尝试对 sqlite 数据库中的一组特定行运行简单的更新查询。它可以工作,但它会清空所有其他行。这是查询:
update table1 set col5 =(select col5 from table2 where table2.id = table1.id)
我知道这非常简单,但我不知道发生了什么。我不能只更新某些行,而不管其余行吗?
I am trying to run a simple Update query on a certain set of rows in my sqlite db. It works, but it NULLs out all the other rows. Here is the query:
update table1 set col5 =(select col5 from table2 where table2.id = table1.id)
I know this is super easy, but I can't figure out what is going on. Can't I only update certain rows, and leave the rest alone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
编辑:
抱歉,没有意识到它是 sqlite。 sqlite 不支持更新子句中的联接。
我最好的猜测是您可以执行以下操作:
try this:
Edit:
Sorry, didn't realise it was sqlite. sqlite doesn't support joins in the update clause.
My best guess is you could do the following:
您正在使用更新的相同列来关联两个表。您应该使用主键或辅助键来关联两个表。
请参阅这个非常相似的问题及其答案: 基于 ID 匹配从一个表到另一个表的 SQL 更新
You are using the same columns you are updating to relate the two tables. You should use a primary or secondary key to relate the two tables.
See this very similar question and its answer: SQL update from one Table to another based on a ID match