• Post Reply Bookmark Topic Watch Topic
  • New Topic

Order BY clause in JPQL

 
Sivapradeep Reddy Duggireddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a SQL query that works fine in MySQL.

SELECT e.email FROM Educator e ORDER BY (e.spocInvig + e.educInvig);

its fetching rows based on the spocinvig and educinvig sum in ascending order.

but in JPQL i'm getting exception like this.
Exception Description: Syntax error parsing the query [SELECT e.email FROM Educator e ORDER BY (e.spocInvig + e.educInvig)], line 1, column 41: syntax error at [(].
Internal Exception: line 1:41: expecting IDENT, found '('

Can anyone suggest me proper JPQL for the given SQL ?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What JPA provider and version are you using?

Did you try just removing the brackets?

SELECT e.email FROM Educator e ORDER BY e.spocInvig + e.educInvig

 
Rajit vreddi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you use jpql then use custom result class to resolve the issue.create a class called ABC and create method getSum(a,b) which returns the sum of two values .
the query looks like

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!