Returning a small extract where column type = text

okay, i’ll explain briefly how to go about it – it involves using nested string functions

first of all, the WHERE clause ensures that all rows returned contain the exact phrase somewhere inside the column value, so you can use INSTR() to find the position where that phrase starts

then use some math to subtract 10 (or however many characters you want in front), but you also have to make sure you don’t end up with a negative number, so you can use GREATEST() function to pick the result of the subtraction or 1, whichever is greater

then just use the SUBSTR() function to extract what you want, with the math calculation just mentioned as the starting position, and anopther calculation for the length of the substring (no need to check for going past the end of the column value, since SUBSTR() will only go up to the end anyway)

simple, if you approach it methodically

1 Like