query to remove all characters after last comma in string

前端 未结 3 1375
醉酒成梦
醉酒成梦 2021-01-08 00:36

i have a mysql table with this sort of data

TACOMA, Washington, 98477

Now i have thousands of such rows. I want the data to be manipulated

3条回答
  •  我在风中等你
    2021-01-08 00:52

    You can use :

    SELECT SUBSTRING_INDEX('TACOMA, Washington, 98477', ',', 2)
    

    You can read more here.

    And the update statement :

    UPDATE my_table
        SET my_col = SUBSTRING_INDEX(my_col, ',', 2)
    

    Where you need to replace my_table with your table name and my_col with the column you need to be updated.

提交回复
热议问题