I use the Haversine query to calculate the distance to property. But even though it works, I did notice I get Warning 1292 messages in PhpMyAdmin and HeidiSQL. I'd like to get rid of those but my search has come to an end.
The query looks like this and as said, works fine but with Warnings:
SELECT t1.id, t1.garage, t1.more_info_url, t1.date_b, t1.mak_id, t2.id AS m_id, t1.is_b, t1.price, t1.lat, t1.lng,
(6371 * ACOS(COS(RADIANS('52.0791005')) * COS(RADIANS(t1.lat)) * COS(RADIANS(t1.lng) - RADIANS('4.2666311')) + SIN(RADIANS('52.0791005')) * SIN(RADIANS(t1.lat)))) AS distance
FROM alert t1
LEFT JOIN users t2 ON t2.id = t1.mak_id
WHERE is_b = 'on'
AND (date_b BETWEEN CURDATE() - INTERVAL '180' DAY AND CURDATE())
AND (t1.price > 180000)
AND (t1.price < 840000)
HAVING DISTANCE < '140'
ORDER BY distance ASC
This results in this error multiple times:
Warning: #1292 Truncated incorrect DOUBLE value: ''
However, when I remove the last line, the ORDER BY clause, all is fine. I have already tried to switch things around, had (single)quotes at every possible position, but I don't understand it anymore.
So, this runs without warnings:
SELECT t1.id, t1.garage, t1.more_info_url, t1.date_b, t1.mak_id, t2.id AS m_id, t1.is_b, t1.price, t1.lat, t1.lng,
(6371 * ACOS(COS(RADIANS('52.0791005')) * COS(RADIANS(t1.lat)) * COS(RADIANS(t1.lng) - RADIANS('4.2666311')) + SIN(RADIANS('52.0791005')) * SIN(RADIANS(t1.lat)))) AS distance
FROM alert t1
LEFT JOIN users t2 ON t2.id = t1.mak_id
WHERE is_b = 'on'
AND (date_b BETWEEN CURDATE() - INTERVAL '180' DAY AND CURDATE())
AND (t1.price > 180000)
AND (t1.price < 840000)
HAVING DISTANCE < '140'
Not sure if it is related, but the only DOUBLE field is "price" in t1. It holds the price of real estate property. I had that surrounded by single quotes in my tests as well. I'm afraifd I have tried all that I know.
Thanks.