Select row with MAX(), or choose one if no MAX() exists
It is possible with UNION ALL. Basically, you have three criteria, therefore you need three SELECT statements. To simplify the select statements, lets create views from your selects as follows:

CREATE VIEW data1 AS
SELECT data.* FROM (
SELECT data.name_id, MAX(data.time_stamp) AS time_stamp
FROM data
WHERE data.time_stamp &lt;= t0
AND data.event &lt;&gt; 'stopped'
GROUP BY data.name_id ) d1
JOIN data
ON data.name_id = d1.name_id AND data.time_stamp = d1.time_stamp AND data.event &lt;&gt; 'stopped';

CREATE VIEW data2 AS
SELECT data.* FROM (
SELECT data.name_id, MAX(data.time_stamp) AS time_stamp
FROM data
WHERE data.time_stamp &lt; t0
AND data.event = 'stopped'
GROUP BY data.name_id ) d1
JOIN data
ON data.name_id = d1.name_id AND data.time_stamp = d1.time_stamp AND data.event = 'stopped';


Now, the select statement will be as easy as this one:

select data2.* 
from data1 inner join data2 
on data1.name_id = data2.name_id and data1.time_stamp = data2.time_stamp
UNION ALL
select data1.* 
from data1 inner join data2 
on data1.name_id = data2.name_id and data1.time_stamp &gt; data2.time_stamp
UNION ALL
select data2.* 
from data1 inner join data2 
on data1.name_id = data2.name_id and data1.time_stamp &lt; data2.time_stamp


SQL Fiddle (I used INT datatype for time_stamp column in the SQL Fiddle, but it shouldn't matter, as the principle is the same for timestamp datatype)

You do not need to use VIEWs, you can embed you queries into the above statement as subqueries. I have used the views just to demonstrate the technique