Hello!

I found the MySQL command on the network:

UPDATE `tablitsa` SET `pole` = REPLACE( pole, 'А', 'Б' ) 

That is, if I ask to replace "A" with "B", then in the field all the words "A" will be replaced with "B". And I need to replace only the first occurring word in the field with the given one, and do not touch the next ones. I read the manual of muscle for a long time, but did not find the answer. How to do it?

Thank!

    1 answer 1

    Use ORDER BY (?) LIMIT 1

    UPDATE tablitsa pole = REPLACE (pole, 'A', 'B') ORDER BY id DESC LIMIT 1

    Similar problem and solution on SO

    • Thanks for the answer! But I realized that I did not write my question to the end. Will the command above replace one value in one field and stop? And I need to change the values ​​of all fields in the table (one word in each), or a specified number of fields. - Ariane
    • @ Arian yes, the command above will only affect one line. The simplest (and possibly effective) approach is to repeat this operation for each field that needs to be changed. If we specify several fields, all of them will be updated, for this reason I do not see other possible solutions - atom-22