http://www.perlmonks.org?node_id=778151


in reply to Re^4: Truncate Data from MySQL
in thread Truncate Data from MySQL

And here is an example:

mysql> SELECT SUBSTRING_INDEX('A bunch of words that you only want the + first fifteen from goes here as this example shows nicely',' ',15) A +S first_15 FROM property LIMIT 1; +--------------------------------------------------------------------- +----+ | first_15 + | +--------------------------------------------------------------------- +----+ | A bunch of words that you only want the first fifteen from goes here + as | +--------------------------------------------------------------------- +----+ 1 row in set (0.00 sec) mysql> SELECT SUBSTRING_INDEX('But what if only a few words?',' ',15) +AS first_15 FROM property LIMIT 1; +-------------------------------+ | first_15 | +-------------------------------+ | But what if only a few words? | +-------------------------------+ 1 row in set (0.00 sec)