I've this query in mysql:
set @dist=20;
set @earthRadius=6371;
SELECT *,SPLIT_STR(posizione_GPS,';', 1) as mylat,SPLIT_STR(posizione_GPS,';', 2) as mylon,(SELECT CALC_DISTANCE(mylat,mylon,cit.lat,cit.lng,@earthRadius) as distance FROM city as cit HAVING distance<@dist ORDER BY distance asc LIMIT 1 ) as distance FROM statistiche as stat
with this, I get the statistics, and given that each statistic is associated with a coordinated GPS, I want to get the name of the city associated with it using a table (the city) that I already in the database. To do this calculation the distance between the coordinates and take the city which is less distant.
CALC_DISTANCE is a custom function for calculate distance between two gps points.
The query works but I need the name of city and if I put in subquery a second column, name:
set @dist=20;
set @earthRadius=6371;
SELECT *,SPLIT_STR(posizione_GPS,';', 1) as mylat,SPLIT_STR(posizione_GPS,';', 2) as mylon,(SELECT nome, CALC_DISTANCE(mylat,mylon,cit.lat,cit.lng,@earthRadius) as distance FROM city as cit HAVING distance<@dist ORDER BY distance asc LIMIT 1 ) as distance FROM statistiche as stat
I get this error
Error Code: 1241. Operand should contain 1 column(s)
How do I get the name of the city? Thanks
The structure of statistiche
table is:
`id` int(11) NOT NULL AUTO_INCREMENT,
`utenti_id` int(11) NOT NULL,
`spots_id` int(11) NOT NULL,
`posizione_GPS` varchar(45) DEFAULT NULL,
`data` date DEFAULT NULL,
`ora` time DEFAULT NULL,
PRIMARY KEY (`id`)
The structure of city
table is:
`id` varchar(10) NOT NULL,
`nome` varchar(100) DEFAULT NULL,
`prov` varchar(45) DEFAULT NULL,
`lat` float(10,6) DEFAULT NULL,
`lng` float(10,6) DEFAULT NULL,
PRIMARY KEY (`id`)