<p>The HAVING clause comes from this piece of code:</p>
<pre><code>// Modify query
$query
    -&gt;addSelect($haversine.' AS distance')
    -&gt;having('distance &lt;= '.$filter-&gt;range)
;
</code></pre>
<p>The variables going into this query modification are:</p>
<ul>
<li><code>$haversine</code> - A complex formula which determines the relative distance of each address from the center point.</li>
<li><code>$filter-&gt;range</code> - The maximum search distance. (defaults to 25)</li>
</ul>
<p>This code exists so that your proximity search results can be <strong>sorted by closest locations</strong>. It will be triggered any time you chain this into your Twig query:</p>
<pre><code>.myFieldHandle(params)
</code></pre>
<p>You can see the full details of how this all ties together in the documentation here:</p>
<blockquote>
<p><a href="https://plugins.doublesecretagency.com/smart-map/sorting-entries-by-closest-locations/" rel="nofollow noreferrer">https://plugins.doublesecretagency.com/smart-map/sorting-entries-by-closest-locations/</a></p>
</blockquote>
<p>There should be no conflict with any existing GROUP BY clause... Smart Map does not set or modify that aspect of the query. And there is no inherent conflict between HAVING and GROUP BY, as demonstrated by <a href="http://www.w3schools.com/sql/sql_having.asp" rel="nofollow noreferrer">this w3schools example</a>, which utilizes both in combination.</p>

CC BY-SA 4.0
2015-09-15T17:36:55.043Z
2021-01-01T06:24:02.863Z
2021-01-01T06:24:02.863Z
Lindsey D
<p>It seems like most Craft queries contain GROUP BY <code>elements</code>.<code>id</code> but this seems to clash with a HAVING clause when using the Smart Map plugin.</p>

<p>Where does this come from and is it possible to override/remove this?</p>

CC BY-SA 3.0
2015-09-15T17:13:06.397Z
Can you edit the question to include the template code you're attempting to use as well any any errors you might be getting?
Brad Bell
<custom-fieldtype><plugin-smartmap>
Smart Map plugin, HAVING SQL and GROUP BY elements.id
# Smart Map plugin, HAVING SQL and GROUP BY elements.id

(Asked by: username_0 on 2015-09-15)

It seems like most Craft queries contain GROUP BY `elements`.`id` but this seems to clash with a HAVING clause when using the Smart Map plugin.

Where does this come from and is it possible to override/remove this?

**Tags:** custom-fieldtype, plugin-smartmap
> **Comments:**
> **username_1**: Can you edit the question to include the template code you're attempting to use as well any any errors you might be getting?  

---

## 1 answers

### Answer by username_2 on 2015-09-15. Score: 1

The HAVING clause comes from this piece of code:
// Modify query
$query
    ->addSelect($haversine.' AS distance')
    ->having('distance <= '.$filter->range)
;

The variables going into this query modification are:

$haversine - A complex formula which determines the relative distance of each address from the center point.
$filter->range - The maximum search distance. (defaults to 25)

This code exists so that your proximity search results can be sorted by closest locations. It will be triggered any time you chain this into your Twig query:
.myFieldHandle(params)

You can see the full details of how this all ties together in the documentation here:

https://plugins.doublesecretagency.com/smart-map/sorting-entries-by-closest-locations/

There should be no conflict with any existing GROUP BY clause... Smart Map does not set or modify that aspect of the query. And there is no inherent conflict between HAVING and GROUP BY, as demonstrated by this w3schools example, which utilizes both in combination.


---

