#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    Is it possible to use parts of a columns value to UPDATE another column in MySql?


    I am trying to do thins:
    Code:
    UPDATE members SET 
    temp_name =  (SELECT everythingbefore @ of column email FROM members) 
    WHERE temp_name = ''
    So I tried and failed:
    Code:
    UPDATE members
    SET    members.temp_name = (SELECT LEFT(`email`, LOCATE("@", `email`)-1) AS `email_left` FROM `members` WHERE LOCATE("@", `email`)>0)
    WHERE temp_name = ''
    Thank you
    Last edited by zxcvbnm; April 24th, 2013 at 02:20 AM.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    1. SUBSTRING_INDEX
    2. You don't need a SELECT or subquery or anything. Just put the "equation" in. Normally.
    Code:
    UPDATE members SET
    temp_name = SUBSTRING_INDEX(email, '@', 1)
    WHERE temp_name = ''
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by requinix
    1. SUBSTRING_INDEX
    2. You don't need a SELECT or subquery or anything. Just put the "equation" in. Normally.
    Code:
    UPDATE members SET
    temp_name = SUBSTRING_INDEX(email, '@', 1)
    WHERE temp_name = ''
    Brilliant, you regexist.

IMN logo majestic logo threadwatch logo seochat tools logo