• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPQL Query Problem.. - Please help :(  RSS feed

Jean Nepton
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to create a query for three days now and can't seem to get it to work correctly. Would really appreciate some guidance... Here's my problem

-I have a function that returns a list of <Event> objects from the query (Event is a class that I created to hold events that occur due to a Problem [another Class I created])
-I want to return the all Events that are associated with a Probelm ID
-I do not want to return Events with identical descriptions (because they are the same event) but instead only the one that occured last (Event Max(e.creationDate))
-I would like to Order By creationDate

I am gues my query may need an INNER JOIN, I also tried the DISTINCT keyword.. Here is the script I feel is the closet to what I want..

SELECT * FROM Event e INNER JOIN FETCH (SELECT DISTINCT e.description, MIN(e.id) AS id FROM Event e GROUP BY e.description) AS tmpTable ON e.description = tmpTable.description AND (e.id = tmpTable.id);

I would super appreciate any help.. THANK YOU in advance..

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!