This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Group by desc in jpql

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having issues in using the 'group by' clause in JPQL.

I need to fetch all the records grouped by their parent records, but need to group by the latest record.(grouping in reverse order)

I tried running 'select * from table_name group by parent_record desc' on mysql and there was no problem.

but when I tried it with JPQL, it started giving exceptions.

please guys, help me if anyone of you have tried this....

thanks in advance.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your jpql query?
 
Sharath Upadhya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for responding. here's my JPQL query.

SELECT x FROM Discussions AS x WHERE x.id IN (SELECT y.id FROM Discussions AS y WHERE y.parentDiscussion IS NOT NULL GROUP BY y.parentDiscussion DESC);

This is just a simplified query. if I remove 'DESC', i am getting the output. but not the expected one.

without DESC, this query fetches only the first comment for any discussion. my requirement is to fetch only the latest comments for all the discussions.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using a sub-query in your jpql query while you're not using a sub-query in your native query?
 
Sharath Upadhya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using multiple sub-queries in both queries.

but I haven't posted those queries just for simplicity. and to give you an idea of what am trying to accomplish.

and it cannot be done without sub-queries as you know it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic