Consulta SQL no válida: select loc.* from (select l.importancia,l.nombre as localidad, p.nombre as provincia, l.longitud, l.latitud, (sqrt(pow(l.longitud-(),2)+pow(l.latitud-(),2))*111.3) as distancia from LOCALIDADES l inner join PROVINCIAS p on l.idProvincia=p.idProvincia where (sqrt(pow(l.longitud-(),2)+pow(l.latitud-(),2))*111.3)<80 and (sqrt(pow(l.longitud-(),2)+pow(l.latitud-(),2))*111.3)>1 order by pow(10/(l.importancia+1),6)*(sqrt(pow(l.longitud-(),2)+pow(l.latitud-(),2))*111.3) limit 10) as loc order by loc.distancia 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 '),2)+pow(l.latitud-(),2))*111.3) as distancia from LOCA' at line 2