Alex
Alex

Reputation: 11

MySQL Query: Trim a string in an entry from some start string to some end string?

I want to write a query to remove '' strings from an entry up until '>' characters.

Say I have:

<a href='somesite'>Text Link</a>

The result should be:

Text Link</a>

Upvotes: 1

Views: 184

Answers (2)

TehShrike
TehShrike

Reputation: 10074

As Christopher and Dor noted, this is almost certainly better done in your code. Still, just for fun, here is how you might do it in MySQL.

SELECT SUBSTRING(`your_column`, LOCATE('>', `your_column`, 
  LOCATE('<', `your_column`)) + 1)
FROM `your_table`;

Upvotes: 1

a1ex07
a1ex07

Reputation: 37364

You can try this:

 SET @tmp = "<a href='somesite'>Text Link</a>";
 SELECT RIGHT(@tmp,LENGTH(@tmp)-LOCATE('>',@tmp));

Note: LOCATE finds the first occurrence of substring; that may or may not what you want.

Upvotes: 1

Related Questions