Chique_Code
Chique_Code

Reputation: 1530

strip the string in MySQL based on specific characters around

I have a column with values that I need to strip. All the strings have the same pattern like the following:

Name
IIT | Cosmo (949446)
MIIT | World (949446)
HNTY | Name (576376)

I only need to grab the value that is in the middle. I was able to get this far:

SUBSTRING_INDEX(`Name`, '|', -1) as `New_Name`

Which gives me back Cosmo (949446), World (949446), Name (576376) The desired output is: Cosmo, World, Name.

Thank you.

Upvotes: 0

Views: 89

Answers (1)

anuragb26
anuragb26

Reputation: 1475

You can use substring_index on your output one more time.

SELECT TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX("IIT | Cosmo (949446)", '|', -1),'(',1))

Upvotes: 1

Related Questions