Question

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?

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 
Was it helpful?

Solution

Much to my delight rather than trying to move items in a table via code, all one must do is right click on the table and "edit table data". And you can move anything to anywhere because it lets you just type in to the field what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top