How to fix an SQL Distinct which is returning duplicate rows.