sql - Postgres: Getting the highest matching log associated with a record? -
i store log follows:
log id | modelid | event 1 | 1 | upped 2 | 1 | downed 3 | 2 | downed 4 | 1 | upped 5 | 2 | multiplexed 6 | 1 | removed
then have models as:
model id | name 1 | model 1 2 | model 2
i want end log entry highest id in log associated model result:
name | event model 1 | removed model 2 | multiplexed
a simple join gives me results:
select * model m left join log l on l.modelid = m.id
but gives me records. missing?
try this
select m.name,l.event log l inner join model m on l.modelid = m.id l.id in ( select max(id) log group modelid )
Comments
Post a Comment