Im having sql issues with the below query, its returning the error...
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''
I cant see why this is throwing an error. When i remove parts of the join it runs correctly.
The jobs of this query is to return a list of properties based on the location given (lat/long) with any matching data from separate offers table along with the url slug for the town and county which are stored in separate tables towns and counties accordingly. If a property has no special offer, it should still be return in the data.
The query is...
SELECT COUNT(agencyid) AS `count_offers`, prop.*, offers.*, twn.slug AS `slug_town`, cnty.slug AS `slug_county`, ROUND(((3959 * acos(cos(radians(50.1854670)) * cos(radians(prop.latitude)) * cos(radians(prop.longitude) - radians(-5.4209100)) + sin(radians(50.1854670)) * sin( radians(prop.latitude)))) * 2),0)/2 AS `distance`
FROM `properties` AS `prop`
JOIN `towns` AS `twn` ON twn.name=prop.town
JOIN `counties` AS `cnty` ON cnty.name=twn.county
LEFT JOIN `offers` ON offers.agencyid = prop.mID
AND
offers.dt_expire>1377985886
AND
(prop.sleeps >= offers.sleeps_min AND prop.sleeps <= offers.sleeps_max)
AND
(
prop.slug_code = offers.the_property
OR
(
(offers.the_property='' OR offers.the_property=NULL)
AND
(
(
prop.county = offers.the_county
AND
prop.town=offers.the_town
)
OR
(
prop.county = offers.the_county
AND
twn.name=offers.the_town
AND
prop.place = offers.the_place
)
OR
prop.county = offers.the_county
OR
prop.region = offers.the_region
OR
prop.country = offers.the_country
)
)
Thanks for you help regarding this.