Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select the last word in a string

Tags:

mysql

I have used

SELECT
    SUBST(field_name, 1, Locate('',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??

like image 975
RDiedrick Avatar asked Dec 17 '22 20:12

RDiedrick


1 Answers

Select SUBSTRING_INDEX(field_name,' ',-1)

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

like image 153
GSto Avatar answered Dec 19 '22 08:12

GSto