We help IT Professionals succeed at work.

MYSQL Query to remove anything after a second '-' including the '-'

Valleriani
Valleriani asked
on
Hello,

Most of my data in a row called 'mtaName' is labelled like this:

"test.com - G1 - 10-11-2011"
"test2.com - G2 - 09-11-2011"

etc..

What I want, is a method to remove anything past the second '-' So taking the example above:

"test.com - G1"
"test2.com - G2"

Without the date pretty much and the extra '-'. Is this possible at all? I know of regexp but not how to use it in this context.

Thank you!
Comment
Watch Question

CERTIFIED EXPERT
Commented:
select SUBSTRING_INDEX(mtaName, '-', 2) from yourtable

Author

Commented:
Thank you !

Explore More ContentExplore courses, solutions, and other research materials related to this topic.