0

I'm trying to figure out how to remove characters in a string in SQL. The nomenclature that is currently in the database looks like this:

Engine - Brand - Category

How can I remove everything and only leave the 'category' portion?

Funnily enough, the code I've been currently using has been doing the opposite of what I want. It's keeping everything and removing the 'category' portion. I've tried leading, both, and trailing and still get the same results

select trim(Both'-' from SUBSTRING_INDEX(ad_group,'- ',2)) 
from farm.GoogleAdGroup GAG
join farm.GoogleCampaign GC on GAG.googlecampaign_id_fk = GC.id
where campaign_type like 'product'
limit 50;

I just need the code to keep the 'category' section and remove everything else.

1 Answer 1

5

try like below

select SUBSTRING_INDEX('Engine - Brand - Category','-',-1)

it will return Category

so in your case

select SUBSTRING_INDEX(ad_group,'-',-1)
Sign up to request clarification or add additional context in comments.

1 Comment

I think that did it! Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.