Get a Quote Right Now

Edit Template

Adding ORDER BY expression

Adding an ORDER BY expression is easy as:

createQueryBuilder("user").orderBy("user.id")

Which will produce:

SELECT ... FROM users user ORDER BY user.id

You can change the ordering direction from ascending to descending (or versa):

createQueryBuilder("user").orderBy("user.id", "DESC")

createQueryBuilder("user").orderBy("user.id", "ASC")

You can add multiple order-by criteria:

createQueryBuilder("user").orderBy("user.name").addOrderBy("user.id")

You can also use a map of order-by fields:

createQueryBuilder("user").orderBy({
    "user.name": "ASC",
    "user.id": "DESC",
})

If you use .orderBy more than once you’ll override all previous ORDER BY expressions.

Adding ORDER BY expression

Adding an ORDER BY expression is easy as:

createQueryBuilder("user").orderBy("user.id")

Which will produce:

SELECT ... FROM users user ORDER BY user.id

You can change the ordering direction from ascending to descending (or versa):

createQueryBuilder("user").orderBy("user.id", "DESC")

createQueryBuilder("user").orderBy("user.id", "ASC")

You can add multiple order-by criteria:

createQueryBuilder("user").orderBy("user.name").addOrderBy("user.id")

You can also use a map of order-by fields:

createQueryBuilder("user").orderBy({
    "user.name": "ASC",
    "user.id": "DESC",
})

If you use .orderBy more than once you’ll override all previous ORDER BY expressions.

Share

Leave a Reply

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