I have a table in SQLite
/* Create a table called NAMES */
CREATE TABLE EVENTS(Id integer , Eventtype integer,value integer,Timestamp DATETIME);
/* Create few records in this table */
INSERT INTO EVENTS VALUES(1,2,1,'2009-01-01 10:00:00'); --ROW1
INSERT INTO EVENTS VALUES(1,2,2,'2007-01-01 10:00:00'); --ROW2
INSERT INTO EVENTS VALUES(2,2,3,'2008-01-01 10:00:00’); --ROW3
What is needed from the query is ROW1 and ROW3. The query should take most latest row based timestamp for duplicate ID & Eventtype combination. ROW1 and ROW2 are having same eventtype and id but ROW1 is latest so it should be picked.