From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

ORDER BY, GROUP BY, and HAVING

ORDER BY, GROUP BY, and HAVING - JPA Tutorial

From the course: Java Persistence with JPA and Hibernate

ORDER BY, GROUP BY, and HAVING

- [Instructor] I'm sure you've used ORDER BY, GROUP BY, and HAVING with SQL, because as I stated at the beginning of the course, SQL is a prerequisite for this course. In JPQL, they work exactly in the same way. Let's first take the ORDER BY clause. This clause specifies the order in which the query results should be arranged. If a query does not include an ORDER BY clause, it produces results in a non-deterministic order. With the ORDER BY clause, you can specify the direction in which you want to order the results. For this, you use the keywords ASC or DESC, where ASC is for ascending order and DESC is for descending order. The default ordering direction is ascending. So when the ascending order is required, you can omit the ASC keyword. Let's start by running the mariadb-init.sql script and the mariadb-07_05.sql script. So everything basically works the same way for JPQL queries. Let's say you want to retrieve a list of books in the ascending order of the author names. So let's go…

Contents