title: MySQL Select From To And Exclude m in returned id result
body: <p>I have SQL that returns this from MySQL:</p>
  
  <pre><code>SELECT id, channel, (y.count) AS channels
  FROM (
      SELECT s.id AS id, c.sort, s.channel
      FROM channels c, streams s
      LEFT JOIN logo l ON s.id=l.channel
      WHERE JSON_SEARCH(s.bouquet, 'one', 1) IS NOT NULL 
      AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL
      AND JSON_SEARCH(c.sort, 'one', s.id) IS NOT NULL
  
      UNION 
  
      SELECT m.marker, c.sort, m.channel
      FROM markers m, channels c, streams s
      LEFT JOIN logo l ON s.id=l.channel
      WHERE JSON_SEARCH(m.bouquet, 'one', 1) IS NOT NULL 
      AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL
      AND JSON_SEARCH(c.sort, 'one', m.marker) IS NOT NULL
      AND s.id=l.channel) ch
  CROSS JOIN (
      SELECT count
      FROM (
          SELECT COUNT(s.id RLIKE '^[0-9]+$') AS count
          FROM streams s, channels c 
          WHERE JSON_SEARCH(s.bouquet, 'one', 1) IS NOT NULL 
          AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL 
          AND JSON_SEARCH(c.sort, 'one', s.id) IS NOT NULL) AS x) AS y
  ORDER BY LOCATE(CONCAT('"', id, '"'), sort);
  </code></pre>
  
  <p>Return From This Query is:</p>
  
  <pre><code>+----+-------------------+
  | id | channel           |
  +----+-------------------+
  | m2 | AA-AA             |
  | 1  | KR_A 1            |
  | 2  | KR_A 2            |
  | 11 | HR_A 3            |
  | 12 | HR_B 1            |
  | m4 | BB-BB             |
  | m3 | CC-CC             |
  | 17 | SR_B 1            |
  | m5 | DD-DD             |
  | m1 | EE-EE             |
  +----+-------------------+
  </code></pre>
  
  <p>I need to modify SQL to when i add <code>m2</code> in Query to return:</p>
  
  <pre><code>1
  2
  11
  12
  </code></pre>
  
  <p>And if i add <code>m3</code> i need to get:</p>
  
  <pre><code>17
  </code></pre>
  
  <p>So i try to add this in beginning of SQL to filter id:</p>
  
  <pre><code>SELECT IF (id BETWEEN 'm2' AND '%m', id, 0) As id, channel, (y.count) AS channels
  </code></pre>
  
  <p>and i get this:</p>
  
  <pre><code>+----+-------------------+----------+
  | id | channel           | channels |
  +----+-------------------+----------+
  | m2 | AA-AA             |        5 |
  | 0  | KR_A 1            |        5 |
  | 0  | KR_A 2            |        5 |
  | 0  | HR_A 3            |        5 |
  | 0  | HR_B 1            |        5 |
  | m4 | BB-BB             |        5 |
  | m3 | CC-CC             |        5 |
  | 0  | SR_B 1            |        5 |
  | m5 | DD-DD             |        5 |
  | m1 | EE-EE             |        5 |
  +----+-------------------+----------+
  </code></pre>
  
  <p>And need to get this:</p>
  
  <pre><code>+----+-------------------+----------+
  | id | channel           | channels |
  +----+-------------------+----------+
  | 1  | KR_A 1            |        4 |
  | 2  | KR_A 2            |        4 |
  | 11 | HR_A 3            |        4 |
  | 12 | HR_B 1            |        4 |
  +----+-------------------+----------+
  </code></pre>
  
  <p>I don't know how to do in SQL query that select from <code>'m2'</code> to next <code>'m'</code> and exclude <code>'m2'</code> and <code>'m'</code> from results....any help?</p>