title: A SQL query to select until SUM(users_count) reaches 1000
body: <p>I need a sql query to select rows from my messages queue, until SUM(users_count) reaches at most 1000. <strong>BUT</strong> there is no problem if there be only one row returned and that row's users_count is greater than 1000.</p>
  
  <p>I need something like: (i added my own keywords)</p>
  
  <pre><code>SELECT * FROM `messages_queue` UNTIL SUM(users_count) &lt; 1000 AT LEAST 1 ROW
  </code></pre>
  
  <p>This is my table structure:</p>
  
  <blockquote>
    <p>messages_queue<br>
      - msg_id<br>
      - msg_body<br>
      - users_count (number of message recieptors)<br>
      - time (insert time)</p>
  </blockquote>