Apply TRIM criteria to entire column in MySQL

Viewed 34

I am trying to use the TRIM function in MySQL to scan an entire column and remove "(inactive)" anywhere it appears in that column. My questions are (1) is this the right application of the TRIM function and (2) how can I specify to scan an entire column and remove wherever the specified condition appears? Note that I cannot just remove all parentheses here since some teams have valid parentheses in their team name.

Sample output currently:

|Team|
|----|
|Research (UX) Team (inactive)|
|Engineering Team|
|Data Team (inactive)|

Desired Output:

|Team|
|----|
|Research (UX) Team |
|Engineering Team|
|Data Team|

I know this is not functioning SQL, but hope you can see what I'm trying to do here:

SELECT TRIM (' (inactive)', team) as team_cleaned
1 Answers

Just replace ' (inactive)' with "nothing" in every field which ends with this string.

update <tablename> set team = replace(team, ' (inactive)', '') where team like '% (inactive)'

Technically you could omit the where clause as other strings would be unaltered.

Related