sql - How do I obtain for each distinct primary key occurrence in a table, the first of an ordered set of rows? -


i want obtain specific set of results table in single query , i'm not being able find how it.

i've got table recording every agent state change (online, offline, away, etc) , time when happened.

i want obtain for each agent id last state change, i.e. considering agents , b, i'd have original table containing:

id | state | datetime

a | online | 29-11-2010

a | offline | 30-11-2010

b | away | 28-11-2010

b | online | 30-11-2010

and want generate output so:

id | state | datetime

a | offline | 30-11-2010

b | online | 30-11-2010

i realize might basic select query, can't put finger on be. mad props if informix compatible :d

how about:

select datetime, id, state table t1   t1.datetime = (select max(t2.datetime) table t2 t2.id=t1.id) 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -