How to choose the last word in a line

I 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 to use last_word, but still get the first word, so I suppose there should be a different way.

+4
source share
2 answers

Well, you could probably do:

 SELECT REVERSE( SUBST( REVERSE( field_name ), 1, LOCATE( ' ', REVERSE( field_name ))) 

This probably won't work if your field has spaces or a single word.

+1
source

All Articles