I need your help. I have two tables, in first (sensors) there is a list of sensors and information about them, in the second table (timegetdata) there are data which were taken by these sensors and there is a time when it occurred. I need to select list of sensors, information about them and the last taken data by them. I have written a query, but it works incorrectly.
SELECT
timegetdata.idsensor,
sensors.type,
sensors.lng,
sensors.lat,
MAX(timegetdata.time) AS time,
timegetdata.carbon_monoxide,
timegetdata.ammonia,
timegetdata.alcohol,
timegetdata.benzene,
timegetdata.smoke,
timegetdata.propane,
timegetdata.butan,
timegetdata.methane,
timegetdata.formaldehyde,
timegetdata.acetone,
timegetdata.toluene
FROM sensors
INNER JOIN timegetdata
ON sensors.idsensor = timegetdata.idsensor
GROUP BY sensors.idsensor