[#1658] Fixed trailing LIMIT clauses for more sophisticated nested selects to prevent issues in DB2