When I run this query I get the above error message, which happens only on Redshift. Is there any other method to select the distinct items in a nested query?