【发布时间】:2017-01-27 17:13:23
【问题描述】:
由于某种原因,使用 PhpMyAdmin 在运行时返回 90 行:
SELECT COUNT(*)
FROM le_wp_posts
WHERE post_content LIKE '%Â%'
但以下仅更新 3 行:
UPDATE le_wp_posts
SET post_content = REPLACE(post_content, 'Â', '')
WHERE post_content LIKE '%Â%'
我也尝试过在UPDATE 语句中省略WHERE 子句。我忽略了导致此问题的任何明显原因吗?或者我可以采取哪些步骤来进一步调查原因?我的 SQL 不是最好的。
【问题讨论】:
-
您是否尝试在 where 条件中使用 select 子句:
WHERE post_content IN (SELECT distinct post_content FROM le_wp_posts WHERE post_content LIKE '%Â%') -
@pat
#1093 - You can't specify target table 'le_wp_posts' for update in FROM clause是UPDATE le_wp_posts SET post_content = REPLACE(post_content, 'Â', '') WHERE post_content IN (SELECT distinct post_content FROM le_wp_posts WHERE post_content LIKE '%Â%')的结果 -
肮脏的解决方案:UPDATE le_wp_posts SET post_content = REPLACE(post_content, 'Â', '') WHERE post_content IN (SELECT distinct post_content FROM (select * from le_wp_posts) as x WHERE post_content LIKE '%Â% ')
-
@Pat 谢谢,在您发帖时正在查看。返回 0 行已更新。我什至更改了连接器字符集以与服务器字符集相关联。我将尝试使用正则表达式替换
标签: mysql sql phpmyadmin