title: MySQL take a range of values based on a column of descending numbers, and then randomize that range
body: <p>I'm having trouble implementing in my code what should be a simple query. I'm trying to take a range of values, say numbered sequentially 1-20 in a column named front_weight and then randomize that query by that column. So far what I've come up with is:</p>
  
  <pre><code>$sql_rand_limit_range = "SELECT * FROM posts 
                           WHERE active='y' 
                           AND front_weight &gt; 0 
                           AND front_weight 
                           IN (SELECT front_weight 
                           FROM posts ORDER BY front_weight DESC LIMIT 0, 20) 
                           ORDER BY RAND()";
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>This version of MySQL doesn't yet support 'LIMIT &amp; IN/ALL/ANY/SOME subquery'
  </code></pre>
  
  <p>I am running MySQL Version 5.1 by the way. I then try to monkey around with the query a little bit trying something like this which in my eyes should work:</p>
  
  <pre><code>$sql_rand_limit_range = "SELECT * FROM posts 
                           WHERE active='y' 
                           AND front_weight &gt; 0
                           ORDER BY RAND() front_weight DESC
                           LIMIT 0, 20";
  
  
  $sql_rand_limit_range = "SELECT * FROM posts 
                           WHERE active='y' 
                           AND front_weight &gt; 0
                           ORDER BY front_weight DESC
                           LIMIT 0, 20 
                           RAND()";
  </code></pre>
  
  <p>But you SQL ninjas can see how far that got me. Any ideas or will I have to do something a little bit more drastic using Php code like randomizing mysqli_fetch_array? </p>
  
  <p>EDIT: I'm getting alot of exotic queries to return something like 15,12,3,17,9,5,11...... I just want to return rows 1-20 in a column randomized. Basically I'm trying to ask in sql parlance how to get this:</p>
  
  <pre><code> ORDER BY front_weight DESC LIMIT 0, 20 
  </code></pre>
  
  <p>to play nice with this:</p>
  
  <pre><code> ORDER BY RAND()
  </code></pre>
  
  <p>I really hope I don't need joins and pseudo-tables, but if I do, so be it.</p>