MODE-1737 Corrected query processing with SELECT DISTINCT and JOIN

When a SELECT DISTINCT is used within a JOIN query, the processing
of the DISTINCT operation results in a failure. This change corrects
that operation, allowing the distinct to work correctly with or
without a JOIN.

Two new test cases were added to first replicate the problem and
then verify the correction does fix the problem.