# QUERY BY EXAMPLE - Add max rows to be returned

**URL:** <https://forum.servoy.com/t/query-by-example-add-max-rows-to-be-returned/20696>\
**Category:** Questions\
**Created:** [February 25, 2022, 7:15pm UTC](https://forum.servoy.com/t/query-by-example-add-max-rows-to-be-returned/20696 "2022-02-25T19:15:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlclark](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dlclark](https://forum.servoy.com/u/dlclark)\
**Post date:** [February 25, 2022, 7:15pm UTC](https://forum.servoy.com/t/query-by-example-add-max-rows-to-be-returned/20696/1 "2022-02-25T19:15:34Z")

</div>

Wondering how to add LIMIT = max rows to query

/\*\*

- param {Numbber} maxReturnedRows
- @properties={typeid:24,uuid:“8F6D517D-15BE-45CA-B84C-34F4C8060305”}  
\*/  
function createSubscribersFullList(maxReturnedRows) {

var query = datasources.db.gob\_business\_system.subscribers.createSelect();

query.result.addPk(); // return only the primary key

// TODO: NEED TO ADD MAX RETURNED ROWS TO QUERY  
// add where clause  
query.where.add(query.columns.electronic\_issues\_remaining .gt(0));

plugins.dialogs.showInfoDialog(“Subscribers Full List for Export”, 'Records found: ’ + foundset.getSize() );

}

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [February 26, 2022, 12:21pm UTC](https://forum.servoy.com/t/query-by-example-add-max-rows-to-be-returned/20696/2 "2022-02-26T12:21:12Z")

</div>

The query builder does not have a limit, limits are used when the query is used, it is not a thing of the query itself.

The most natural way is to just not traverse the foundset beyond the maxReturnedRows.  
Since a foundset is loading in a lazy way, the other records and pks are never read from the database.

If this is not feasible, you can read all pks (with limit) in a dataset and load the foundset with those.  
Note that the pks are loaded twice from the database in that case.

```auto
	var dataset = databaseManager.getDataSetByQuery(query, maxReturnedRows)
	foundset.loadRecords(dataset)

```

Rob
