I have a table similar to this
id message state timestamp
1 abcd Heartbeat 1970-01-01 01:00
2 efgh Start 1970-01-01 02:00
3 sdcvsd Stop 1970-01-01 02:30
4 efgh Start 1970-01-01 03:00
5 sdcvsd Stop 1970-01-01 03:30
6 dsdfsd Heartbeat 1970-01-01 04:10
7 sdcsc Heartbeat 1970-01-01 04:20
8 sewwdf Heartbeat 1970-01-01 04:30
What I would like to do is query this table in PHP and show the rows, but only show the latest row of Heartbeat, because it is very repetitive and I only need to know when the last one happened. All other states will echo even if they are repetitive. So the output would be (newest at the top):
8 sewwdf Heartbeat 1970-01-01 04:30
5 sdcvsd Stop 1970-01-01 03:30
4 efgh Start 1970-01-01 03:00
3 sdcvsd Stop 1970-01-01 02:30
2 efgh Start 1970-01-01 02:00
I have only been able to leave it out with
mysqli_query($con, " SELECT * FROM msg WHERE state <> 'Heartbeat' ORDER BY id DESC LIMIT 16 " );
I don't think I can use GROUP BY or DISTINCT for more than one state.
How can I query only the latest Heartbeat state without effecting other states or remove the older ones in the PHP echo?

mysqli_query($con, " SELECT * FROM msg GROUP BY id ORDER BY id DESC LIMIT 16" );try this1970-01-01 01:00? I think some problem is there?SELECT * FROM msg GROUP BY(state) HAVING timestamp = MAX(timestamp) ORDER BY id DESC LIMIT 16