I have a table called sensorvalue like this:
station_id sensor_id Timestamp Value
----------------------------------------------------------
1 1 2013-09-04 12:00:00 12.2
1 2 2013-09-04 12:00:00 13.1
1 3 2013-09-04 12:00:00 13.2
1 1 2013-09-04 12:05:00 12.1
1 2 2013-09-04 12:05:00 14.1
1 3 2013-09-04 12:05:00 13.2
1 1 2013-09-04 12:10:00 12.5
1 2 2013-09-04 12:10:00 13.3
1 3 2013-09-04 12:10:00 14.1
I need a MySQL query that gets all the latest values of all three sensors of station with station_id 1. I wonder if this is possible with one MySQL statement.
I've managed to get the data out of the table, but not in an efficient way. Now I first SELECT all different sensors for station 1 and afterthat I call another MySQL SELECT statement foreach sensor. Some of the stations have over 10 sensors, so with this approach I need at least 11 MySQL statements to get the data out of the database.
I would like to include this in one MySQL statement. Is that possible? And how?