I have the following table in SQL Server 2008:
CREATE TABLE tbl (ID INT, dtIn DATETIME2, dtOut DATETIME2, Type INT) INSERT tbl VALUES (1, \'05:00\', \'6:00\', 1
You must include the column tbl.dtOut in your select list so it knows what to order on.
SELECT DISTINCT tbl.id, tbl.dtOut FROM tbl LEFT JOIN tbl AS t1 ON tbl.type = t1.type AND tbl.dtIn = t1.dtIn ORDER BY tbl.dtOut ASC