Select * From table as a Where a.time=( Select max(b.time) From table as b Where ( b.from=a.from and b.to=a.to ) Or ( b.from=a.to and b.to=a.from ) )