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 ') AND List = 1 GROUP BY distance ORDER BY distance ASC LIMIT 10' at line 17 : SELECT EstDetails.RecordID, EstDetails.Name, Town, EstDetails.description, website, EstDetails.email, reviews.id AS Rid, EstablishmentType.TYPE, Details.DPrice, SQRT( POW( 69.1 * ( latitude - 52.347130000000000 ) , 2 ) + POW( 69.1 * ( 1.271014000000037 - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance FROM EstDetails INNER JOIN EstablishmentType ON EstablishmentType.ID = EstType LEFT JOIN reviews ON EstDetails.RecordID = reviews.est AND reviews.display = 1 AND reviews.type = 1 LEFT JOIN Details ON Details.RecordID = EstDetails.RecordID WHERE latitude IS NOT NULL AND EstType IN(1,2,4,5,7) AND EstDetails.RecordID NOT IN() AND List = 1 GROUP BY distance ORDER BY distance ASC LIMIT 10