I have a project using Spring Data JPA that consumes data from a table full of addresses. One of the columns of this table is the city. I would like to get a distinct list o
This can be achieved using the @Query annotation as:
public interface AddressRepository extends CrudRepository {
@Query("SELECT DISTINCT a.city FROM Address a")
List findDistinctCity();
}
Then, a call to addressRepository.findDistinctCity() would return the distinct city names.
A sample application is available on Github for review. Run integration test as mvn clean test to verify the approach.