Get distinct before top for query