Is there a way to separate a column into two ?
The column its like this
BRAND/PRODUCT
And I wanted to insert them into 2 new columns BRAND and PRODUCT
Thanks
Is there a way to separate a column into two ?
The column its like this
BRAND/PRODUCT
And I wanted to insert them into 2 new columns BRAND and PRODUCT
Thanks
Use LOCATE
to find the /
, and SUBSTR
to grab the parts of the string before and after it.
UPDATE table
SET brand = SUBSTR(brand_product, 1, LOCATE('/', brand_product)-1),
product = SUBSTR(brand_product, LOCATE('/', brand_product)+1)
Essentially splits the field value. The "1" in the first one gets the first text segment, the "-1" in the second one gets the last text segment.
UPDATE `table`
SET `brand` = SUBSTRING_INDEX(`brand_product`, '/', 1),
`product` = SUBSTRING_INDEX(`brand_product`, '/', -1);
Output:
| brand_product | brand | product |
+---------------+-------+---------+
| one/two | one | two |
See: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index