Help With A Simple MYSQL Query

Discussion in 'Databases' started by mjwoodi, Jan 5, 2010.

  1. #1
    Hi,

    I need a query to run into my mysql databse to find and replace if a condition is met.

    Basically I want to-

    Find and replace the text 'xord' with 'xord4' in the campaign column but only if the network column = content

    My table is called KW

    The code I have so far is below, but how do I tell it to only replace xord if the campaign column = content?

    update KW set campaign = replace(campaign, ‘xord’, ‘xord4’)
    Code (markup):
     
    mjwoodi, Jan 5, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Here's the sql:

    UPDATE KW SET KW.campaign = "xord4"
    WHERE (((KW.network)="content") AND ((KW.campaign)="xord"));
    
    PHP:
    The above code assumes that the network field is literally the string 'content'. If you meant content to be a variable then you should adjust it as such.
     
    plog, Jan 5, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    The above would only work if the entire value of the column is 'xord'.

    If the column contains a string 'there is a xord...', the above would not apply. Which are you trying to accomplish?
     
    jestep, Jan 5, 2010 IP
  4. mjwoodi

    mjwoodi Peon

    Messages:
    436
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That code doesnt work sorry =\

    Yes the entire campaign column is currently set to 'xord'

    However where the network column is equal to 'content' I want to replace 'xord' with 'xord4'

    Thanks for your time
     
    mjwoodi, Jan 5, 2010 IP
  5. meameajones

    meameajones Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes this looks right
     
    meameajones, Jan 5, 2010 IP
  6. mjwoodi

    mjwoodi Peon

    Messages:
    436
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ahhh I tried it again and it worked, not sure what I did wrong the first time.

    Thanks for all your help guys!
     
    mjwoodi, Jan 5, 2010 IP