Tuesday 27 August 2013

Populating a column by extracting a value from other column in the same table

Populating a column by extracting a value from other column in the same table

I have a table callInfo and it looks like this:
+----+------------------------------------------------------------------------------------------------------------------------------------+
| id | idUrl
| collectionId |

|
+----+------------------------------------------------------------------------------------------------------------------------------------+
| 1 |
id?books.0.levelOfDetail=high&books.0.shopId=727&books.0.type=books&collectionId=20092014&type=seasonPassSource
| |
| 2 |
id:call3?books.0.levelOfDetail=high&books.0.shopId=123&books.0.type=books&collectionId=16645&type=seasonPassSource
| |
| 3 | id:call3?maxDepth=1&parentMixId=777&type=mixSource
| |
| 4 |
idSet:call3?keyword=%22FOO%20BAR%20.%5E%24*%2B%3F%7C%28%29%7B%7D%5B%5D%22&type=wishListSource
| |
| 5 | idSet:call3?books.0.levelOfDetail=high&books.0.shopId=727
| |
| 6 |
idSetSource.0.booksNumber=2&collectionId=16645&books.0.levelOfDetail=high&books.0.type=books&type=seasonPassSource
| |
| 7 | idSet:call3?keyword=hero&type=wishListSource
| |
+----+-------------------------+----------------------------------------------------------------------------------------------------------+
I have created a new column called collectionId in the table callInfo, but
the are many records in the table for which I need to update this column
value.
I need to extract the value of collectionId from idUrl column and put it
in collectionId column.
it should look like this
+----+------------------------------------------------------------------------------------------------------------------------------------+
| id | idUrl
| collectionId |

|
+----+------------------------------------------------------------------------------------------------------------------------------------+
| 1 |
id?books.0.levelOfDetail=high&books.0.shopId=727&books.0.type=books&collectionId=20092014&type=seasonPassSource
| 20092014 |
| 2 |
id:call3?books.0.levelOfDetail=high&books.0.shopId=123&books.0.type=books&collectionId=16645&type=seasonPassSource
| 16645 |
| 3 | id:call3?maxDepth=1&parentMixId=777&type=mixSource
| NULL |
| 4 |
idSet:call3?keyword=%22FOO%20BAR%20.%5E%24*%2B%3F%7C%28%29%7B%7D%5B%5D%22&type=wishListSource
| NULL |
| 5 | idSet:call3?books.0.levelOfDetail=high&books.0.shopId=727
| NULL |
| 6 |
idSetSource.0.booksNumber=2&collectionId=16645&books.0.levelOfDetail=high&books.0.type=books&type=seasonPassSource
| 16645 |
| 7 | idSet:call3?keyword=hero&type=wishListSource
| NULL |
+----+-------------------------+----------------------------------------------------------------------------------------------------------+
I need to do this in MySQL. Any ideas?

No comments:

Post a Comment