Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the string after a specific substring in mysql

I want to retrieve the last part of a large string in mysql after occurence of a particular substring. Please advice about how to do that.

For e.g. the main string contains "New Delhi is capitalof India". "Berlin is capitalof Germany".

I need to retrieve only India and Germany. I want know how to retrieve the data occuring after the specific substring like 'capitalof'.

I need to do this in mysql.

like image 366
pallab sen Avatar asked Jun 16 '15 05:06

pallab sen


People also ask

How do you get a specific substring from a string in SQL?

Use the SUBSTRING() function. The first argument is the string or the column name. The second argument is the index of the character at which the substring should begin. The third argument is the length of the substring.

How do I search for a letter in a string in MySQL?

MySQL LOCATE() Function The LOCATE() function returns the position of the first occurrence of a substring in a string. If the substring is not found within the original string, this function returns 0. This function performs a case-insensitive search.

How do I slice a string in MySQL?

The SUBSTRING() function extracts a substring from a string (starting at any position). Note: The SUBSTR() and MID() functions equals to the SUBSTRING() function.


1 Answers

You can use substring_index

select
substring_index(title,'capitalof',-1)
from table1

DEMO

like image 51
M Khalid Junaid Avatar answered Sep 25 '22 12:09

M Khalid Junaid