MySQL:将REPLACE与JOIN一起使用? [英] MySQL: using REPLACE with a JOIN?

查看:163
本文介绍了MySQL:将REPLACE与JOIN一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文本字段中替换多个个不同的单词.

I need to replace multiple different words in a text field.

搜索和替换值在另一个表中.

The search and replace values are in another table.

例如texts-table是:

For example the texts-table is :

The Quick Brown Fox
The Dirty Red Bandana

带有这样的替换表:

SearchValue         ReplaceValue
  Quick               Slow
  Fox                 Wolf
  Dirty               Clean
  Bandana             Hat

替换后的记录将变为:

The Slow Brown Wolf
The Clean Red Hat

是否可以通过JOIN做到这一点?

Is it possible to do this with a JOIN?

类似的东西:

UPDATE texts_table AS tt
CROSS JOIN values_table AS vt
SET tt.Text= REPLACE(tt.Text, vt.SearchValue, vt.ReplaceValue)

我尝试了一些不同的方法,但是无法用它来替换文本字段中的 all 字符串.

I tried some different ways, but couldn't get it to replace all strings in the text field.

推荐答案

例如,您需要指定一个Join条件:

You need to specify a Join condition, for example, like this:

UPDATE texts_table AS tt
INNER JOIN values_table AS vt 
   on tt.valueId = vt.valudId /*or whatever the join condition*/ 
SET tt.Text= REPLACE(tt.Text, vt.SearchValue, vt.ReplaceValue)

UPDATE 的语法中所指定条款:

As specified in the syntax of the UPDATE clause:

UPDATE [LOW_PRIORITY] [IGNORE] table_reference

table_references子句列出了联接中涉及的表. JOIN语法进行描述.

这篇关于MySQL:将REPLACE与JOIN一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆