MYSQL UPDATE command

Discussion in 'MySQL' started by jacka, Feb 6, 2008.

  1. #1
    Hi

    I have a small problem in finding and replacing text in a field.

    I know how to use UPADTE command and have lookup up regexp, but I can not combine them together.
    I wish to change every occurrence of a myfield in mytable that has got QF in it to change it to GFI.
    a typical data is : abcQFxyz to chnage to abcQFIxyz.

    I got as far as:
    UPDATE mytable SET myfield = QFI WHERE part_number REGEXP 'QF';
    but I know that wrong.

    Thanks for your help.
    :D
     
    jacka, Feb 6, 2008 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Maybe something like this:

    UPDATE mytable SET myfield = REPLACE(myfield, 'QF', 'QFI');
     
    SoKickIt, Feb 6, 2008 IP
  3. adams2on

    adams2on Peon

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    adams2on, Feb 8, 2008 IP