title: Limit the number of rows in a LENGTH statement
body: <p>I have the following mysql code in a view</p>
  
  <pre><code>SELECT 
  threadid,
  SUM(LENGTH(pagetext)-LENGTH(REPLACE(pagetext, ' ', ''))+1)
  
  FROM post
  GROUP by threadid
  </code></pre>
  
  <p>This count the number of words in each column with the same "threadid", and return the results grouped by the threadid. It works fine, but I want to limit the words counted only for the first 5 rows in each column. How can this be achieved?</p>
  
  <p>Table Structure</p>
  
  <pre><code>+-----------------+-------------+
  | threadID        | pagetext    |
  +-----------------+-------------+
  | 3               | some text   |
  | 3               | other text  |
  | 5               | text        |
  +-----------------+-------------+
  </code></pre>
  
  <p>The view returns</p>
  
  <pre><code>+-----------------+-------------+
  | threadID        | count       |
  +-----------------+-------------+
  | 3               | 4           |
  | 5               | 1           |
  +-----------------+-------------+
  </code></pre>
  
  <p>I'm looking to limit the count number to only n rows for each threadID. For example, if I limit the count to only 1 row, the threadID "3" will have a "count" of 2.</p>