fixed querying distinct results from DB