I am currently doing large circle distance calculations in a table in MySQL. The table is as follows:
+----------+---------+---------+ | venue_id | lat | lng | +----------+---------+---------+ | 1 | 1.23456 | 2.34567 | +----------+---------+---------+ | 2 | 1.23456 | 2.34567 | +----------+---------+---------+ | 3 | 1.23456 | 2.34567 | +----------+---------+---------+
However, when I try to create a COUNT() return result, MySQL returns an empty result set.
For example, the following query returns no results:
SELECT COUNT(*) AS total, ( 3959 * Acos(Cos(Radians('52.97682200')) * Cos(Radians(lat)) * Cos( Radians(lng) - Radians(-0.02210000)) + Sin(Radians(52.97682200)) * Sin(Radians(lat))) ) AS distance FROM wv_venue_locations HAVING distance < 5 ORDER BY distance
However, running the same query without the COUNT(*) AS total field produces the expected results 6.
Can anyone guess why this is happening, and how can I fix it?
As a post-script to the above, the following works fine:
SELECT Count(*) AS total, ( 3959 * Acos(Cos(Radians(53.18335000)) * Cos(Radians(lat)) * Cos( Radians(lng) - Radians(-0.29600000)) + Sin(Radians(53.18335000)) * Sin(Radians(lat))) ) AS distance FROM wv_venue_locations WHERE lat >= 52.64017900 AND lat <= 53.72650900 AND lng >= -0.94998000 AND lng <= 0.35798000
The above correct outputs:
+-------+-------------------+ | total | distance | +-------+-------------------+ | 224 | 27.93840157954865 | +-------+-------------------+
source share