fix bug where LIMIT/OFFSET were applied before distinct
now they are applied last
closes MB-8697