how do i move txt from one column to another

Posted by bodhi926 on Stack Overflow See other posts from Stack Overflow or by bodhi926
Published on 2013-11-01T03:37:00Z Indexed on 2013/11/01 3:54 UTC
Read the original article Hit count: 99

Filed under:
|
|
|

I need to take an address that consists of "city, state" from column "location" and populate 2 new columns "city" and "state" but leave location the way it is, now I have done this with a SUBSTRING_INDEX command but I have to run the command everytime to do this, how can I make it stick? thanks in advance. also here is my substring code....

SELECT  distinct id, first_name, last_name,
SUBSTRING_INDEX(location, ' ,', 1) AS City,
SUBSTRING_INDEX(location, ' ,', -1) AS State,
SUBSTRING_INDEX(seeking,  ' ,', 1) AS Seeking_1,
SUBSTRING_INDEX(seeking,  ' ,', -1) AS Seeking_2,
SUBSTRING_INDEX(interests,' ,', 1) AS Interests_1,
SUBSTRING_INDEX(interests,' ,', -1) AS Interests_2,
SUBSTRING_INDEX(interests,' ,', 1) AS Interests_3
FROM my_contacts 

© Stack Overflow or respective owner

Related posts about index

Related posts about substring