String Manipulation in MySQL

Discussion in 'MySQL' started by T0PS3O, Dec 6, 2006.

  1. #1
    I have a column of usernames I need to export as email addresses to csv. So I need to add the @domain.com after the username.

    I tried stuff like...

    UPDATE list SET user = user + '@domain.com' WHERE user = 'john'
    Code (markup):
    ...but that sets it to 0.

    PHP style gives an error:

    UPDATE list SET user = user . '@domain.com' WHERE user = 'john'
    Code (markup):
    Is this actually possible? If numeric additions are possible, string manupilation must be as well, right?

    Something like the SUBSTRING function but then more like PHPs str_replace I guess. REPLACE does it but not by character position.

    Any ideas?
     
    T0PS3O, Dec 6, 2006 IP
  2. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #2
    You're close, should be
    
    UPDATE list SET user = concat(user, "@domain.com") WHERE user = "john"
    
    Code (sql):
     
    dct, Dec 6, 2006 IP