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?

  • 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
    Commented Sep 15, 2015 at 17:13

1 Answer 1


The HAVING clause comes from this piece of code:

// Modify 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:


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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.