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