How to select the last word in a string
I have used
SELECT
SUBST(field_name, 1, Loc开发者_Go百科ate('',field_name)) AS first_word
FROM
table_name
and it works for the first word so I tried using last_word but still get the first word so I guess there must be a differet way??
Select SUBSTRING_INDEX(field_name,' ',-1)
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index
Well, you probably could do:
SELECT REVERSE( SUBST( REVERSE( field_name ), 1, LOCATE( ' ', REVERSE( field_name )))
This likely won't work if your field has trailing spaces or is a single word.
精彩评论