Christian Meisinger wrote:

You could use the LEFT() function to return for instance the 200 first
characters:

SELECT LEFT(article,200) AS start_of_article
 FROM articletable WHERE ...

You could also use the SUBSTRING_INDEX() function, if your lines are
separated with \r\n:

SELECT SUBSTRING_INDEX(article,'\r\n',2) AS two_first_lines
 FROM articletable WHERE ...

<URL: http://dev.mysql.com/doc/mysql/en/string-functions.html >

Is there a method which uses word counting?


you could count spaces.

like above:

SELECT SUBSTRING_INDEX(article,' ',40) AS two_first_lines FROM
articletable WHERE ...

Right, that would give a fixed number of words (where words are anything between spaces), regardless of length returned. To get a relatively constant length, but not break in the middle of a word, you could modify Roger's first suggestion


  SELECT LEFT(article, LOCATE(' ', article, 200) - 1) AS art_start
  FROM articletable WHERE ...

to get the beginning of the article up to (but not including) the first space after position 200.

Be careful of what happens when the article is not as expected. In the first case (SUBSTRING_INDEX), you get the entire article if it doesn't have the requested number of spaces. In the second case (LEFT and LOCATE), you get an empty string if there is no space after the chosen position (200 in the example).

Michael



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to