We need to turn LIMIT into a TOP clause on the SELECT STATEMENT

@param orderByInfo
@param offsetInfo
@param limitInfo
@private
973088
function _processOrderByOffsetLimit(orderByInfo,offsetInfo,limitInfo){
    // save the OFFSET AND LIMIT nodes with the ORDER BY node
    orderByInfo.node.msSQLOffsetNode=offsetInfo.node;
    if (limitInfo) orderByInfo.node.msSQLLimitNode=limitInfo.node;
    // remove the OFFSET and LIMIT nodes from the filters so they don't get processed later.
    filters.splice(offsetInfo.index,1);
    if (limitInfo) filters.splice(limitInfo.index,1);
  }
71855
private static int getPreviousPageOffset(final int offset, final int limit) {
        return hasFullPreviousPage(offset, limit) ? getPreviousFullPageOffset(offset, limit) : getFirstPageOffset();
    }
1282305
private void onLimit(StringBuilder builder) {
        if (Integer.MAX_VALUE != maxResult) {
            builder.append(CQLTranslator.LIMIT);
            builder.append(isSingleResult ? 1 : this.maxResult);
        }
    }
1154105
public void parse(final SelectStatement selectStatement) {
        Optional<LimitValue> offset = Optional.absent();
        Optional<LimitValue> rowCount = Optional.absent();
        while (true) {
            if (lexerEngine.skipIfEqual(PostgreSQLKeyword.LIMIT)) {
                rowCount = buildRowCount(selectStatement);
            } else if (lexerEngine.skipIfEqual(PostgreSQLKeyword.OFFSET)) {
                offset = buildOffset(selectStatement);
            } else {
                break;
            }
        }
        if (offset.isPresent() || rowCount.isPresent()) {
            setLimit(offset, rowCount, selectStatement);
        }
    }
648240
public static String genLimitSQL(Integer offset, Integer limit) {
		StringBuilder sb = new StringBuilder();
		if (limit != null) {
			sb.append(" limit ");
			if(offset != null) {
				sb.append(offset).append(",");
			}
			sb.append(limit);
		}
		return sb.toString();
	}
1353343
public function applyLimit(&$sql, $offset, $limit)
    {
        $offset = (int) $offset;
        $limit = (int) $limit;

        if ($limit >= 0) {
            $sql .= ' LIMIT ' . ($offset > 0 ? $offset . ', ' : '') . $limit;
        } elseif ($offset > 0) {
            $sql .= ' LIMIT ' . $offset . ', 18446744073709551615';
        }
    }
159486
private void onLimit(StringBuilder builder)
    {
        builder.append(CQLTranslator.LIMIT);
        builder.append(this.maxResult);
    }
685996
public function select(
        $table,
        $conditions = null,
        $fields = null,
        $order = null,
        $limit = null,
        $offset = null
    )
    {
        if (is_null($fields)) {
            $fields = "*";
        }

        $queryString = "SELECT {$fields} FROM {$table} ";

        if (!is_null($conditions)) {
            $queryString .= "WHERE {$conditions} ";
        }

        if (!is_null($order)) {
            $queryString .= "ORDER BY {$order} ";
        }

        if (!is_null($limit)) {
            $queryString .= "LIMIT {$limit} ";
        }

        if (!is_null($offset) && !is_null($limit)) {
            $queryString .= "OFFSET {$offset} ";
        }


        $queryString .= ";";

        $this->query($queryString);

        return $this->countRows();
    }
1238044
final public void selectQuery() throws ParseException {
    select();
    from();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case WHERE:
      where();
      break;
    default:
      jj_la1[0] = jj_gen;
      ;
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case ORDER_BY:
      sort();
      break;
    default:
      jj_la1[1] = jj_gen;
      ;
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case LIMIT:
      limit();
      break;
    default:
      jj_la1[2] = jj_gen;
      ;
    }
    jj_consume_token(0);
  }
888452
private void _buildStatement(
                    final List<Order> orders,
                    final Limit limit,
                    final StringBuilder stmt
                    )
    {
        stmt.append( _selectClause ).append( _fromClause ).append( _whereClause );
        if (orders == null) {
            stmt.append( _orderClause );
        } else {
            _buildOrderClause( orders, stmt );
        }

        if (isLimitEnabled()) {
            if (limit == null) {
                stmt.append( _limitClause );
            } else {
                _buildLimit( limit, stmt );
            }
        }
    }
1060770
public void setOrdering(String ordering) {

        if (ordering != null) {
            m_ordering = new CmsSimpleQueryFragment(ordering, Collections.<Object> emptyList());
        } else {
            m_ordering = null;
        }
    }
1021397
function(table, limit, page, query, fields)
    {
        if (this._doneLoading)
            return;

        var _this = this;

        // Execute -- add orderBy and ascending?
        var args = [table, limit, page, query, fields];
        if (this._orderBy) {
            args.push(this._orderBy);
            args.push(this._ascending);
        }

        var p = this.dataService.query.apply(this.dataService.query, args)

        // Pack results back into <T> and add it to our _results array
        .then(function(results) {
            results.forEach(function(r) {
                var obj = new _this._T();
                _(r).each(function(value, key) {
                    obj[key] = value;
                });
                _this._results.push(obj);
            });

            // If we hit the last page
            if (results.length !== limit)
                _this._doneLoading = true;

            return _this._results;
        });

        return p;
    }
1249411
@Nonnull
  public Query limit(int limit) {
    QueryOptions newOptions = new QueryOptions(options);
    newOptions.limit = limit;
    return new Query(firestore, path, newOptions);
  }
878434
public function search($term, $limit, $offset, $orderBy = null)
    {
        $qb = $this->createQueryBuilder('m');

        $qb->where('m.name LIKE :term')
            ->andWhere('m.status IN (:statuses)')
            ->setParameters(array(
                'term' => '%'.$term.'%',
                'statuses' => array(0, 1),
            )
        );

        if ($limit) {
            $qb->setMaxResults($limit);
        }

        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery()->getResult();
    }
19133
protected void doLoad(int offset, int limit) {
        dataSource.load(new LoadConfig<>(offset, limit, table.getView().getSortContext(),
                table.getView().getOpenCategories()), new LoadCallback<T>() {
            @Override
            public void onSuccess(LoadResult<T> loadResult) {
                setOffset(loadResult.getOffset());
                totalRows = loadResult.getTotalLength();
                table.setVisibleRange(loadResult.getOffset(), loadResult.getData().size());
                table.loaded(loadResult.getOffset(), loadResult.getData());
                updateUi();
            }

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Load failure", caught);
                //TODO: What we need to do on failure? May be clear table?
            }
        });
    }
706845
protected void addSorting(CmsSelectQuery select, TableAlias users, CmsUserSearchParameters searchParams) {

        boolean ascending = searchParams.isAscending();
        String ordering = getSortExpression(users, searchParams);
        if (ascending) {
            ordering += " ASC";
        } else {
            ordering += " DESC";
        }

        select.setOrdering(ordering);
    }
758409
def _fix_slicing_order(self, outer_fields, inner_select, order, inner_table_name):
        
        # Using ROW_NUMBER requires an ordering
        if order is None:
            meta = self.query.get_meta()
            column = meta.pk.db_column or meta.pk.get_attname()
            order = '{0}.{1} ASC'.format(
                inner_table_name,
                self.connection.ops.quote_name(column),
            )
        else:
            alias_id = 0
            # remap order for injected subselect
            new_order = []
            for x in order.split(','):
                # find the ordering direction
                m = _re_find_order_direction.search(x)
                if m:
                    direction = m.groups()[0]
                else:
                    direction = 'ASC'
                # remove the ordering direction
                x = _re_find_order_direction.sub('', x)
                # remove any namespacing or table name from the column name
                col = x.rsplit('.', 1)[-1]
                # Is the ordering column missing from the inner select?
                # 'inner_select' contains the full query without the leading 'SELECT '.
                # It's possible that this can get a false hit if the ordering
                # column is used in the WHERE while not being in the SELECT. It's
                # not worth the complexity to properly handle that edge case.
                if x not in inner_select:
                    # Ordering requires the column to be selected by the inner select
                    alias_id += 1
                    # alias column name
                    col = '{left_sql_quote}{0}___o{1}{right_sql_quote}'.format(
                        col.strip(self.connection.ops.left_sql_quote+self.connection.ops.right_sql_quote),
                        alias_id,
                        left_sql_quote=self.connection.ops.left_sql_quote,
                        right_sql_quote=self.connection.ops.right_sql_quote,
                    )
                    # add alias to inner_select
                    inner_select = '({0}) AS {1}, {2}'.format(x, col, inner_select)
                new_order.append('{0}.{1} {2}'.format(inner_table_name, col, direction))
            order = ', '.join(new_order)
        return outer_fields, inner_select, order