Get a Quote Right Now

Edit Template

Adding GROUP BY expression

Adding GROUP BY expression

Adding a GROUP BY expression is easy as:

createQueryBuilder("user").groupBy("user.id")

Which will produce the following SQL query:

SELECT ... FROM users user GROUP BY user.id

To add more group-by criteria use addGroupBy:

createQueryBuilder("user").groupBy("user.name").addGroupBy("user.id")

If you use .groupBy more than once you’ll override all previous GROUP BY expressions.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *