skip to Main Content

I’m working on MySQL Workbench 8.0. And I would like to remove all the characters after "-" or "("

Organic Rice Sticks - Spinach OR Organic Rice Sticks (Pack of Three)

To

Organic Rice Sticks

Does MySQL have the functionality to do this?

EDIT: I would also like to remove the characters after "[" such as Organic Rice Sticks [Pack of Three] to Organic Rice Sticks

2

Answers


  1. select substring_index(substring_index(mysterycolumnname, '-', 1), '(', 1)
    

    Though given your sample data, you want to actually remove characters after ' -' or ' ('. Or remove trailing spaces:

    select rtrim(substring_index(substring_index(mysterycolumnname, '-', 1), '(', 1))
    
    Login or Signup to reply.
  2. Select SUBSTRING(ProductName, 1, LOCATE(‘ ‘, ProductName) – 1) from Products

    You can try above here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search