Refs #4594 - Adds ability to remove DISTINCT modifier from SQL by passin...

...g 'distinct' => false in $options. That does not fix the ticket, but gives ability to optimize queries without breaking compatibility.

https://github.com/Elgg/Elgg/pull/418 rebased on master branch