开发者

SQL statement to find last word in string

I have a table with a text field that contains one or more words, separated by spaces. I want to isolate the last word in that text field. For example if the table contained:

|col1 |
+-----+
|a    |
|b c  |
|d e f|

I want a query that will return:

|re开发者_C百科sult|
+------+
|a     |
|c     |
|f     |

Thanks in advance!

Barry

P.S. I am running MySQL 5.1


SELECT SUBSTRING_INDEX(TRIM(col1), ' ', -1) FROM table;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜