Select the first 50 words of an article

I’m cleaning up my code snippets and i found the following little trick in one of them that i’ve removed. Assuming that different words are separated by spaces we can use SUBSTRING_INDEX as following:

SELECT SUBSTRING_INDEX(body,' ',50) AS dn FROM mytable

This entry was posted on Wednesday, January 18th, 2006 at 02:57 and is filed under SQL. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.