
create or replace view messages_current as
  select id, domain, action, class, item, tstamp, payload
    from messages m1
    where id = (select max(id) from messages m2
	  where m2.domain = m1.domain and m2.action = m1.action
	    and m2.class = m1.class and m2.item = m1.item);
