MySQL Query Building and geo points
<p>I have MySQL Table called ads , each ad has a unique <code>id</code> and geo point field called <code>location</code> ,</p>

<p>What I am doing now is counting how many ads near a certain point <code>POINT(46.52167 23.81167)</code> and it works fine using this SQL Query</p>

<pre><code>SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location) &lt; 0.17536759746391475;
</code></pre>

<p>Sometimes I have 20 points or more on a request and I want to run this query for all of them , It takes a lot of time because I use multiple queries combined together.</p>

<p>for example I have two points <code>POINT(46.52167 23.81167)</code> and <code>POINT(46.72417 23.51167)</code> I use the following SQL </p>

<pre><code>SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location) &lt; 0.17536759746391475;
SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.72417 23.51167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.72417 23.51167)'),
            location) &lt; 0.17536759746391475;
</code></pre>

<p>My Question : Is there any way to optimize and combine these two queries into one ? using grouping or having or any method or algorithm ?</p>