I'm using sensors to get temperature and humidity every X minutes.
I've one table for sensors and one table for their results.
I want to get the latest measurement for every sensor (MAX(date)).
I'm using this:
SELECT id_sens, pos_sens, temp_res, humi_res, MAX(date_res) FROM tb_sensors INNER JOIN tb_results ON tb_sensors.pk_sens = tb_results.fk_sens GROUP BY id_sens ORDER BY id_sens
I'm expecting to get:
but the result is:
I've got the latest date mixed with the first id, position, temperature and humidity ever written.
How can I resolve this issue?