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

I wondered about that as well, but having had a look at the MySQL reference, I can't see anything that would do what the OP needs.

I'm no expert though. Is it possible? Can anyone enlighten?

--
use JAPH;
print JAPH::asString();

Replies are listed 'Best First'.
Re^4: Truncate Data from MySQL
by stevemayes (Scribe) on Jul 08, 2009 at 05:46 UTC

    SUBSTRING_INDEX() : Return a substring from a string before the specified number of occurrences of the delimiter

    And if you look at the actual description you see that positive n (count of the delimiter) returns the string to the left of the delimiter whilst negative n (e.g. -2) return the substring to the right of the nth delimiter. Now image that the delimiter is ' ' (which can be explicitly stated in Mysql as '<space>').

      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)