Support for DISTINCT ON when joining.

When joining now a DISTINCT ON will be used on the primary key of the
table being querried to prevent duplicates being present in the result
set. This may or may not be a good idea and the option for distinct may
need to be created later.