如何使用 where 子句的 select 更新字段?

发布于 2024-09-12 05:33:58 字数 411 浏览 1 评论 0原文

我有表格,其中一个称为“文章”,另一个称为“链接”。

我想从表链接中获取 url 和标题,并使用链接表中的数据更新文章表。我不确定该怎么做。链接表有引用它的article_id,任何人都可以帮忙吗?

这是一些伪代码,如果有帮助的话?

UPDATE articles 
   SET articles.url, 
       articles.title = (SELECT links.url, 
                                links.title 
                           FROM links 
                          WHERE articles.id = links.article_id)

这有道理吗?

I have tables, 1 called "articles" and another called "links".

I want to take the url and title from the table links and update the articles table with the data from the links table. I am unsure how to do this. The links table has article_id referenced to it, can anyone help?

Here is some pseudo-code if this helps?

UPDATE articles 
   SET articles.url, 
       articles.title = (SELECT links.url, 
                                links.title 
                           FROM links 
                          WHERE articles.id = links.article_id)

Does this make sense?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-09-19 05:33:58
UPDATE articles, links
SET articles.url = links.url,  
articles.title = links.title
WHERE articles.id = links.article_id

或者

UPDATE articles
INNER JOIN links ON (articles.id = links.article_id)
SET articles.url = links.url,  
articles.title = links.title
UPDATE articles, links
SET articles.url = links.url,  
articles.title = links.title
WHERE articles.id = links.article_id

OR

UPDATE articles
INNER JOIN links ON (articles.id = links.article_id)
SET articles.url = links.url,  
articles.title = links.title
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文