Adding a LIMIT
expression is easy as:
createQueryBuilder("user").limit(10)
Which will produce the following SQL query:
SELECT ... FROM users user LIMIT 10
The resulting SQL query depends on the type of database (SQL, mySQL, Postgres, etc). Note: LIMIT may not work as you may expect if you are using complex queries with joins or subqueries. If you are using pagination, it’s recommended to use take
instead.