Closed aftabshk closed 4 months ago
Spring Data JPA is not in charge of generating SQL from JPQL. How would you even express such a query in JPQL?
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
It's true, I also cannot realize distinct on column query where we have several columns. @aftabshk Have you found a workaround? I think it can only be a native query.
Spring Data JPA is not in charge of generating SQL from JPQL. How would you even express such a query in JPQL?
I think that question was clear. We cannot use JPQL query with distinct on single column when query selects several. I think it might be:
entityManager.createQuery("select distinct(c.unit) e.id from Table e join fetch e.compositions c where c is not empty"
I am using following versions:
PostgresSQL - 14.5 Spring Boot - 3.1.11 Spring Data Jpa - 3.1.11
I have two Entity classes like below:
I want to perform a distinct query based on a particular column like below. In postgres this gives me rows by performing a distinct only on id column.
select distinct on (q.id) q.id, q.quote, q.author_id, a.name from quote q join author a on q.id = a.id
I have tried two ways so far:
But this will create a query like below which is not what I require. This query applies distinct over all the projections
select distinct q.id, q.quote, q.author_id, a.name from quote q join author a on q.type = ?
This will also create a query like below which is not what I require:
select distinct q.id, q.quote, q.author_id, a.name from quote q join author a on q.type = ?
Is there any way to do this? Something like below:
findDistinctOnByType("id", "type")
.Or please suggest if there's any other workaround