Get distinct before top for query

When the query contains both DISTINCT and TOP, get DISTINCT before TOP.