Say if I have a table:
CREATE TABLE T ( TableDTM TIMESTAMP NOT NULL, Code INT NOT NULL );
And I insert some rows:
Try this:
SELECT MIN(TableDTM) TableDTM, Code FROM ( SELECT T1.TableDTM, T1.Code, MIN(T2.TableDTM) XTableDTM FROM T T1 LEFT JOIN T T2 ON T1.TableDTM <= T2.TableDTM AND T1.Code <> T2.Code GROUP BY T1.TableDTM, T1.Code ) X GROUP BY XTableDTM, Code ORDER BY 1;