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 wo开发者_C百科uld 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'
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'
精彩评论