本文介绍了根据另一个表中的列更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案假设 good_table 中可能有多个不是帖子的条目,您需要细化您的加入条件以仅选择帖子"
Assuming there could be multiple entries in good_table that are not posts, you need to refine your join condition to only select 'posts'
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'更多推荐
根据另一个表中的列更新表
发布评论