开发者

how do I update fields with a select for the where clause?

开发者 https://www.devze.com 2023-01-09 06:06 出处:网络
I have tables, 1 called \"articles\" and another called \"links\". I want to take the url and title from the table links and update th开发者_如何学编程e articles table with the data from the links ta

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

I want to take the url and title from the table links and update th开发者_如何学编程e 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号