distinct will return duplicate entries and cause primary key related err...

a sql fix, a pet casting fix