简体   繁体   English

根据另一个表中的列更新表

[英]Update table based on column in another table

UPDATE bad_table,good_table
SET bad_table.post_content = good_table.post_content    
WHERE bad_table.post_type = 'post' AND 
bad_table.post_date = good_table.post_date

This is my code for getting one whole column from one table to another, based on a date value, which I found is unique for this case. 这是我的代码,用于根据日期值从一个表到另一个表获取一个完整列,我发现这个案例是唯一的。 However, I get nothing. 但是,我一无所获。

If I select this, like so: 如果我选择这个,就像这样:

SELECT * FROM bad_table,good_table
WHERE bad_table.post_type = 'post' AND 
bad_table.post_date = good_table.post_date

...I get all the rows I would expect. ...我得到了我期望的所有行。 What am I doing wrong? 我究竟做错了什么?

Assuming there could be multiple entries in good_table that are not posts, you need to refine your join condition to only select 'posts' 假设good_table中可能有多个不是帖子的条目,您需要优化您的加入条件以仅选择“帖子”

    update bad_table
inner join good_table on bad_table.post_date = good_table.post_date 
       and bad_table.post_type = good_table.post_type
       set bad_table.post_content = good_table.post_content
     where bad_table.post_type = 'post'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM