Q:

Selecting last action from log table

I have some kind of log table which registers every interesting event that an agent has. Basically, if it's logged or busy or whatever. 
With that said, imagine this:
    agent       event           dateTime
1   foo       logged        2012-03-01 14:23:36
2   foo       unlogged      2012-03-01 14:24:36
3   baz       logged        2012-03-01 14:25:36
4   bar       logged        2012-04-01 08:24:36
6   bar       unlogged      2012-04-01 08:25:36
7   foo       logged        2012-04-01 08:26:36

I want to retrieve just the ones that are "logged" so, in this example, it would be foo (id 7) and baz (id 3) (obsesive worker here...) 
I've been thinking but didn't find the trick.
Does anyone knows?

A:

Updated
*Updated once again to retrieve last status*
SELECT a.* 
FROM table1 a
INNER JOIN 
(SELECT agent, 
 MAX(`dateTime`) as lastActionDt, 
 MAX(CASE WHEN `event`='logged' THEN `dateTime` END) as last_logged_in_event,
 MAX(CASE WHEN `event`='unlogged' THEN `dateTime` END) as last_logged_out_event 
 FROM table1 
 GROUP BY agent
 HAVING last_logged_out_event IS NULL OR last_logged_in_event>last_logged_out_event
) b ON
 (b.agent = a.agent AND b.lastActionDt = a.`dateTime`)

I assume it's impossible to have unlogged event without corresponding logged. If it's possible, then HAVING should look HAVING  last_logged_in_event IS NOT NULL AND(last_logged_out_event IS NULL OR last_logged_in_event>last_logged_out_event).

