Exclude Duplicate Posts in this SELECT Query

Remove

DISTINCT

And add

GROUP BY $wpdb->posts.ID

before ‘ORDER BY’

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)