How to use DISTINCT in my code