title: Trouble with SQLite SQL Query
body: <p>I'm trying to run the following query in SQLite 3:</p>
  
  <pre><code>SELECT *,
    DISTANCE(latitude, longitude, ?, ?) AS "distance"
  FROM "country"
  WHERE "id" NOT LIKE ?
  HAVING "distance" &lt;= ?
  ORDER BY "distance" ASC;
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <blockquote>
    <p>SQLSTATE[HY000]: General error: 1 a
    GROUP BY clause is required before
    HAVING</p>
  </blockquote>
  
  <p>I don't understand why SQLite wants me to group results, but still I tried the following:</p>
  
  <pre><code>SELECT *,
    DISTANCE(latitude, longitude, ?, ?) AS "distance"
  FROM "country"
  WHERE "id" NOT LIKE ?
  GROUP BY "id"
  HAVING "distance" &lt;= ?
  ORDER BY "distance" ASC;
  </code></pre>
  
  <p>And I also tried this:</p>
  
  <pre><code>SELECT *,
    DISTANCE(latitude, longitude, ?, ?) AS "distance"
  FROM "country"
  WHERE "id" NOT LIKE ?
  GROUP BY "distance"
  HAVING "distance" &lt;= ?
  ORDER BY "distance" ASC;
  </code></pre>
  
  <p>No errors, but all records were returned (even those having <code>"distance" &gt; ?</code>). I also tried doing:</p>
  
  <pre><code>SELECT *,
    DISTANCE(latitude, longitude, ?, ?) AS "distance"
  FROM "country"
  WHERE "id" NOT LIKE ?
    AND "distance" &lt;= ?
  ORDER BY "distance" ASC;
  </code></pre>
  
  <p>Same output, all records were returned. I've double checked - the distance is being correctly calculated... I've no idea what's wrong with this query, can someone help me out?</p>