Mysql query to select records where the sum of a column's values is in a given variable range <p>I've been trying to write a query to select all records from a table where the sum of a column's values is between a variable range.</p> <p>Here's what I came up with so far:</p> <pre><code>$result = mysql_query(' SELECT * FROM table WHERE SUM(column) BETWEEN $Range1 AND $Range2 ORDER BY RAND()); </code></pre> <p>However when I try to loop through the above query with the mysql_fetch_object function it gives me a common error (The supplied argument is not a valid result).I've tried different ways of writing it but still come up short</p> <p>So I tried the query using aliases you guys provided but still get the same error.</p> <pre><code>$result = mysql_query(' SELECT column1, SUM(column2) AS Total FROM table GROUP BY column1 HAVING Total BETWEEN $Range1 AND $Range11 ORDER BY RAND()'); </code></pre>