Let's say I have a random text, such as this one:
Lorem ipsum dolor sit amet consectetur adipiscing elit.
Using MySQL, I'd like to search for a given keyword and get a return along with immediate words surrounding my keyword.
Example:
Select * from table where keyword like "%amet%"
This returns entire text. But I need a query which would return only following text:
sit amet consectetur
So, the word I've search for, plus previous and next word.
--
Additionally, In case I search for keyword elit, return should be (as there is no word after 'elit'):
adipiscing elit
In case I search for keyword Lorem, return should be (as there is no word before 'Lorem'):
Lorem ipsum
Can this be somehow done? Using regex or detection of spaces, using MID or some sort of a substring?