Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:24:26+00:00 2026-05-14T03:24:26+00:00

I have two MySQL tables, and I want to find and replace text strings

  • 0

I have two MySQL tables, and I want to find and replace text strings in one using data in another.

Table texts:

+---------------------+
|      messages       |
+---------------------+
| 'thx guys'          |
| 'i think u r great' |
| 'thx again'         |
| ' u rock'           |
+---------------------+

Table dictionary:

+--------------+---------------+
| bad_spelling | good_spelling |
+--------------+---------------+
|    'thx'     |    'thanks'   |
|    ' u '     |    ' you '    |
|    ' r '     |    ' are '    |
+--------------+---------------+

I want SQL to go through and look at every row in messages and replace every instance of bad_spelling with good_spelling, and to do this for all the pairs of bad_spelling and good_spelling.

The closest I have gotten is this:

update texts, dictionary
set texts.message = replace(texts.message,
                            dictionary.bad_spelling,
                            dictionary.good_spelling)

But this only changes “thx” to “thanks” (in two rows) and does not go on to replace ” u ” with ” you” or ” r ” with ” are .”

Any ideas how to make it use all the rows in dictionary in the replace statement?


PS forgot to mention that this is a small example and in the real thing I will have a lot of find/replace pairs, which may get added to over time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:24:26+00:00Added an answer on May 14, 2026 at 3:24 am

    I’ve never used MySql, so this is just a theory based on my other database work. When reading the other answers, trying to use REPLACE(), I thought I could post this and get someone with MySql syntax experience a few ideas to make a set base solution.

    here is some SQL Server code to that does most of the work for you:

    DECLARE @Source table (Texts varchar(50))
    INSERT @Source VALUES ('thx guys')
    INSERT @Source VALUES ('i think u r great')
    INSERT @Source VALUES ('thx again')
    INSERT @Source VALUES ('u rock')
    
    DECLARE @Dictionary table (bad_spelling varchar(50), good_spelling varchar(50))
    INSERT @Dictionary VALUES ('thx', 'thanks')
    INSERT @Dictionary VALUES ('u', 'you')
    INSERT @Dictionary VALUES ('r', 'are')
    
    SELECT
        t.Texts,COALESCE(d.good_spelling,c.ListValue) AS WordToUse
        FROM @Source                                     t
            CROSS APPLY dbo.FN_ListToTable(' ',t.Texts)  c
            LEFT OUTER JOIN @Dictionary                  d ON c.ListValue=d.bad_spelling
    

    OUTPUT:

    Texts              WordToUse
    ------------------ ---------
    thx guys           thanks
    thx guys           guys
    i think u r great  i
    i think u r great  think
    i think u r great  you
    i think u r great  are
    i think u r great  great
    thx again          thanks
    thx again          again
    u rock             you
    u rock             rock
    
    (11 row(s) affected)
    

    It would be better to use a “real” PK than the actual “Texts” in the query above, but the OP doesn’t list many columns in that table, so I use “Texts”.

    Using SQL Server you need to use a some funky XML syntax to join the rows back together (so I won’t show that code, as it doesn’t matter), but using MySql’s GROUP_CONCAT() you should be able to concatenate the word rows back together into phrase rows.

    the code for the (SQL Server) split function and how it works can be found here: SQL Server: Split operation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mysql tables and i want to merge the results of these
I have two MySQL tables, j and t, with a third normalising table, jt.
I was thinking that I would have two tables for mysql. One for storing
I have two tables in mySQL, notably accounts and subscriber_data. I want to use
I have two columns of type timestamp(6) in my table. I want to find
Currently, I have two MySQL tables. First table stores relation between the friend and
I have two tables, one for bookings and one for room allocations. Booking table
This is a mysql question. I have two tables one called forms and the
I have two similar tables in different databases, I want to insert into one
I have two MySQL tables something like this: tool_owners: tool_owners_id | user_id | ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.