I have two tables Service
and Status
. In the table of services there is only name
andid
| id | name |
|----|-------|
| 1 | Test1 |
| 2 | Test2 |
And a status table like this
| id | status | service_id | timestamp |
|----|--------|------------|---------------------------|
| 1 | OK | 1 | October, 15 2015 09:03:07 |
| 2 | OK | 1 | October, 15 2015 09:08:07 |
| 3 | OK | 2 | October, 15 2015 10:05:23 |
| 4 | OK | 2 | October, 15 2015 10:15:23 |
I want to get data like this
| id | name | status | timestamp |
|----|-------|--------|---------------------------|
| 1 | Test1 | OK | October, 15 2015 09:08:07 |
| 2 | Test2 | OK | October, 15 2015 10:15:23 |
Last status with service data. I tried this statement
SELECT ser.id, ser.name, a.status, a.timestamp
from Service ser
inner join (select * from status
order by Status.timestamp
DESC limit 1) as a
on a.service_id = ser.id
But I only get
| id | name | status | timestamp |
|----|-------|--------|---------------------------|
| 2 | Test2 | OK | October, 15 2015 10:15:23 |
How can I change the statement to get what I want?
For testing SQL Fiddle
source
share