Fix mssql issue

I reverted my refactoring of this query as it seems to be causing a MS SQL problem:
https://moodle.org/mod/forum/discuss.php?d=238212

I have it removing duplicates by getting Moodle to create the results arrays for the queries using a string, which means array_merge should remove duplicates.